OpenGL 2D

Started by
4 comments, last by Lord_Evil 14 years ago
I want to create a 2D game and display everything by pixels. Here is my code so far:
void ResizeGraphics()
{
    // Get new window size
    RECT rect;
	int Width, Height;
	GLfloat aspect;

    GetClientRect(hWnd, &rect);
    Width = rect.right;
    Height = rect.bottom;
    aspect = (GLfloat)Width / Height;

    // Adjust graphics to window size
    glViewport(0, 0, Width, Height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
	//gluPerspective(45.0, aspect, 1.0, 100.0);
    glOrtho(0, Width, Height, 0, 0, 1);
    glMatrixMode(GL_MODELVIEW);
}
Bad thing is, it doesn't render anything on the screen. Can someone please explain to me what I am doing wrong?
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Advertisement
Show your draw calls.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Here you go:

void DrawGraphics(){    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glLoadIdentity();    glTranslated(0, 0, -10);    glBegin(GL_TRIANGLES);    glColor3d(1, 0, 0);    glVertex3d(10, 20, 0);    glVertex3d(15, 20, 0);    glVertex3d(20, 25, 0);    glEnd();    SwapBuffers(hDC);}
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
You're drawing your object outside of the box you specified with glOrtho. You've specified a znear and zfar of 0 and 1, but you're drawing objects at -10.

The z for the object has to be between 0 and 1, or alternatively, expand your near and far planes.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Still nothing... I fixed the translate thing. Maybe some sample code?
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Try to disable back face culling: glDisable(GL_CULL_FACE)
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement