I'm trying to get an OpenGL texture to render onscreen in 2D. I know it seems really simple, but I'm an OpenGL newbie and this has been giving me some trouble.
No matter what I try, it is showing up white.
I've seen the other questions like OpenGL renders texture all white and checked everything on the checklist, but I can't seem to figure out the source, and I would really appreciate any help.
I'm pretty sure I've just made some stupid mistake somewhere, and have tried scrapping my code and rewriting a couple times.
Here is the code relevant to the window being run from the main method.
//Window is a custom wrapper for GLFWwindow
Window thirdwindow(window_width, window_height, "Three");
thirdwindow.show();
thirdwindow.setPosition(300, 300);
ThirdLoop(thirdwindow);
Here is ThirdLoop:
static void ThirdLoop(Window& win)
{
GLuint tex = loadBMP("cat.bmp");
auto size = win.getWindowSize();
win.beginDraw();
while (running)
{
if (win.isClosing())
running = false;
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the color buffer (background)
DrawImage(size, tex);
win.render();
Update();
}
}
And DrawImage (apologies for the odd indenting here, a copy-paste thing)
void DrawImage(const Size<int>& size, GLuint texture) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, size.width, 0.0, size.height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
// Draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glVertex3f(0, 100, 0);
glTexCoord2f(1, 1); glVertex3f(100, 100, 0);
glTexCoord2f(1, 0); glVertex3f(100, 0, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
loadBMP was taken from http://www.opengl-tutorial.org/beginners-tutorials/tutorial-5-a-textured-cube/.
