In scene, others are not drawing after calling shader.use()
vic4key opened this issue · 5 comments
Hi,
I'm testing the project Text Rendering but I got an issue that others are not drawing except the text rendering.
Example, I added a triangle but it did not displayed. I find out because of calling the method shader.use()
.
If I close 2 lines use shader.use()
at text_rendering.cpp#L80 and text_rendering.cpp#L220, the triangle is displayed normal.
I googled and found a releated topic but seem not worked https://www.reddit.com/r/opengl/comments/inr2ab/call_to_gluseprogram_seems_to_reset_my_scene/
Please take a look at the file LearnOpenGL\src\7.in_practice\2.text_rendering\text_rendering.cpp
that I added these codes:
while (!glfwWindowShouldClose(window))
{
// input
// -----
// processInput(window);
// render
// ------
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// BEGIN MY CODE
glColor3f(0.F, 1.F, 0.F);
glBegin(GL_POLYGON);
{
glVertex2f(-0.5F, -0.5F);
glVertex2f(+0.5F, -0.5F);
glVertex2f(+0.0F, +0.5F);
}
glEnd();
// END MY CODE
RenderText(shader, "This is sample text", 25.0f, 25.0f, 1.0f, glm::vec3(0.5, 0.8f, 0.2f));
RenderText(shader, "(C) LearnOpenGL.com", 540.0f, 570.0f, 0.5f, glm::vec3(0.3, 0.7f, 0.9f));
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
Hope we can resolve this issue.
Thanks
It looks like you're mixing old immediate OpenGL (using stuff like glBegin) code with modern shader-based OpenGL code which is the text rendering is based on. I have no idea whether mixing these two will work, and if it does, I'm not much of an expert on the immediate mode of OpenGL so I can't really help you there.
I'm a newbie in OpenGL so I would like to confirm your advice that: We should not mixing old style (using stuff like glBegin, etc) with only modern shader-based OpenGL, or should not mixing old style in all modern OpenGL programming and replaced using by new method like VBO, PBO, etc?
Thank @JoeyDeVries
I would recommend not to mix both styles all together unless you're familiar with both styles, which you are not.
My recommendation is to properly learn modern OpenGL which gives you more control, flexibility, and that style of graphics programming is what's being used all over the world. You'll become a much better graphics programmer that way. See if you can work through the 'Getting Started' chapters, that should give you a pretty good idea and start of how modern OpenGL works and you can then display your triangle correctly with the text rendering next to it :)
Thank your advice. I'm following your tuts, your training process is very clear, step by step. Hope I can pass them all. Thank you for sharing.
No probs, best of luck, enjoy!