I just recently started using C++ and OpenGL and I am running into an issue. I am not totally sure what I am doing so could you please tell me what I am doing wrong and what I could improve?
Here is the problem:
I can't see to get a textured quad to render at all. I've tried a bunch of different ways and even asked people who claimed to know C++ and they said they didn't see any obvious issues.
I am using the following libraries:
- GLFW (For input/window callbacks)
- GLUT (For OpenGL)
Here is my code:
///In class "Game"
virtual void render() {
int ww, hh;
glfwGetWindowSize(gameWindow, &ww, &hh);
glLoadIdentity();
gluOrtho2D(0, ww, hh, 0);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gameRoom->render();
glfwSwapBuffers(gameWindow);
glPopMatrix();
}
///In class "Sprite"
void render(int index, int x, int y, float xscale, float yscale)
{
float tcx1, tcx2, tcy1, tcy2;
tcx1 = (float)frames[index].x / base_width;
tcx2 = (float)(frames[index].x + frame_width) / base_width;
tcy1 = (float)frames[index].y / base_height;
tcy2 = (float)(frames[index].y + frame_height) / base_height;
float vx1, vx2, vy1, vy2;
vx1 = (x - Game::gameView->x) / Game::gameView->width;
vx2 = (x + frame_width * xscale - Game::gameView->x) / Game::gameView->width;
vy1 = (y - Game::gameView->y) / Game::gameView->height;
vy2 = (y + frame_height * yscale - Game::gameView->y) / Game::gameView->height;
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture);
glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
glTexCoord2f(tcx1, tcy1); glVertex2f(vx1, vy1);
glTexCoord2f(tcx2, tcy1); glVertex2f(vx2, vy1);
glTexCoord2f(tcx1, tcy2); glVertex2f(vx1, vy2);
glTexCoord2f(tcx2, tcy1); glVertex2f(vx2, vy1);
glTexCoord2f(tcx1, tcy2); glVertex2f(vx1, vy2);
glTexCoord2f(tcx2, tcy2); glVertex2f(vx2, vy2);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}
When I run the game all I get is a black screen... Please help!