Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui Dockspace not working when viewports are enabled #7609

Closed
Platforming-Mayhem opened this issue May 20, 2024 · 11 comments
Closed

ImGui Dockspace not working when viewports are enabled #7609

Platforming-Mayhem opened this issue May 20, 2024 · 11 comments
Labels

Comments

@Platforming-Mayhem
Copy link

Platforming-Mayhem commented May 20, 2024

Version/Branch of Dear ImGui:

Branch: docking

Back-ends:

imgui_impl_glfw.cpp
imgui_impl_opengl3.cpp

Compiler, OS:

Windows 10

Full config/build information:

No response

Details:

I'm setting up imgui docking and multi-viewports, I'm trying to create a viewport window that renders my game's graphics in an imgui window. However when I use:

if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
ImGui::DockSpaceOverViewport();
}

it causes my render textures to clear and erase themselves so nothing gets rendered to screen or the viewport.

Screenshots/Video:

with ImGui::Dockspace
image
without ImGui::Dockspace
image

Minimal, Complete and Verifiable Example code:

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
ImGui::DockSpaceOverViewport();
}

ImGui::Render();
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}

@PathogenDavid
Copy link
Contributor

This is most likely an issue on your end. You should use a graphics debugger like RenderDoc to investigate.

@Platforming-Mayhem
Copy link
Author

@PathogenDavid Why does it start working as soon as I disable ImGui::DockSpaceOverViewport();?

@PathogenDavid
Copy link
Contributor

Hard to say without debugging your app, which is why I recommended looking at a graphics debugger.

@Platforming-Mayhem
Copy link
Author

For some reason the vs output changes depending on whether dockspace is active or not. If it is active, gl_position goes to NaN. If it is inactive, the values are correct.
No Dockspace
image
Dockspace
image

@Platforming-Mayhem
Copy link
Author

It seems like my program doesn't allow:
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
and:
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
ImGui::DockSpaceOverViewport();
}
to run at the same time for some reason.

@ocornut
Copy link
Owner

ocornut commented May 21, 2024

It's possibly an issue in your code and you may be not sharing the relevant code.
It's ambiguous what those vertices you posted are (vertices for what?).
Try to confirm if your render-to-texture is valid in both cases.
Use Metrics/Debugger to inspect our draw calls.

@Platforming-Mayhem
Copy link
Author

My textures are valid, it seems like my vertex positions become invalid. I'm not sure what is causing it to become invalid.
image
this is my vertex shader if it helps.

@ocornut
Copy link
Owner

ocornut commented May 21, 2024

it seems like my vertex positions become invalid.

OpenGL uses a bunch of global state, so it is possible that some of the state we alter inside ImGui_ImplOpenGL3_RenderDrawData() are altering your render because it doesn't explicitly set them up.

@ocornut
Copy link
Owner

ocornut commented May 21, 2024

My textures are valid, it seems like my vertex positions become invalid. I'm not sure what is causing it to become invalid.

Again, this can means different things and is very ambiguous to read without code. We still don't know how you are rendering the things that breaks.

If you have a texture working, then you can submit your framebuffer using ImGui::Image(), and then I don't understand what this shader is about because you shouldn't need one. So it seems like you are may doing something else but I cannot guess what it is.

I also don't know if by texture you are referring to the texture used as part of the render toward generating your framebuffer-rendered-to-texture, or if you are talking about your framebuffer-rendered-to-texture. Without code we can only guess.

@Platforming-Mayhem
Copy link
Author

Through testing a bunch I've found out that my model matrix is getting screwed up for some reason. Also just to give some context, I am using ImGui to display a render texture using ImGui::Image. However the part that is going wrong happens during the rendering of the render texture, and the render texture is rendering a scene that contains a gameObject with a texture that looks like this:
watermark
The GameObject's texture is being passed correctly, but the render texture isn't rendering anything.

void K::Transform::PassModelMatrix(K::Transform* parent) 
{
	K::Matrix4x4 globalModelMatrix = K::Matrix4x4::IdentityMatrix();

	if (parent == nullptr)
	{
		//World space transforms are in control
		*this->localScale = *this->scale;
		*this->localRotation = *this->rotation;
		*this->localPosition = *this->position;
		//Scaling Matrix
		globalModelMatrix.m[0][0] *= this->scale->x;
		globalModelMatrix.m[1][1] *= this->scale->y;
		globalModelMatrix.m[2][2] *= this->scale->z;
		//Rotation Matrix
		globalModelMatrix = K::Matrix4x4::Matrix_MultiplyMatrix(globalModelMatrix, *K::Quaternion::Euler(this->rotation)->QuaternionToMatrix());
		//Translation Matrix
		globalModelMatrix.m[3][0] += this->position->x;
		globalModelMatrix.m[3][1] += this->position->y;
		globalModelMatrix.m[3][2] += this->position->z;
	}
	else
	{
		if (*this->position != this->previousPosition)
		{
			*this->localPosition = *this->position;
			K::Matrix4x4 invert = K::QuickInverse(parent->modelMatrix);
			K::MultiplyMatrixVector(*this->position, *this->localPosition, invert);
		}
		if (*this->rotation != this->previousRotation)
		{
			*this->localRotation = *this->rotation - *parent->rotation;
		}
		if (*this->scale != this->previousScale)
		{
			*this->localScale = *this->scale / *parent->scale;
		}

		//Local space transforms are in control
		*this->scale = *this->localScale * *parent->scale;
		*this->rotation = *this->localRotation + *parent->rotation;
		K::MultiplyMatrixVector(*this->localPosition, *this->position, parent->modelMatrix);
		//Scaling Matrix
		globalModelMatrix.m[0][0] *= this->scale->x;
		globalModelMatrix.m[1][1] *= this->scale->y;
		globalModelMatrix.m[2][2] *= this->scale->z;
		//Rotation Matrix
		globalModelMatrix = K::Matrix4x4::Matrix_MultiplyMatrix(globalModelMatrix, *K::Quaternion::Euler(this->rotation)->QuaternionToMatrix());
		//Translation Matrix
		globalModelMatrix.m[3][0] += this->position->x;
		globalModelMatrix.m[3][1] += this->position->y;
		globalModelMatrix.m[3][2] += this->position->z;
	}

	this->modelMatrix = globalModelMatrix;

	this->previousPosition = *this->position;
	this->previousRotation = *this->rotation;
	this->previousScale = *this->scale;
}

This is the code(^) used to construct the model matrix, this->modelMatrix is the final model matrix that gets passed to the shader.

void GameObject::PassTransformationMatrix()
{
	if (this->parent == nullptr) 
		this->GetTransform()->PassModelMatrix();
	else 
		this->GetTransform()->PassModelMatrix(this->parent->GetTransform());
	glUniformMatrix4fv(glGetUniformLocation(this->material->GetShader()->shader, "modelMatrix"), 1, GL_FALSE, &this->GetTransform()->modelMatrix.m[0][0]);
}

@Platforming-Mayhem
Copy link
Author

I managed to fix the issue, it was an issue with how I setup my rotation Matrix and how it was applying to the model matrix. It ended up exploding everything. Thanks for helping me, even though it wasn't an issue with your codebase :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants