Jump to content
  • Advertisement
Sign in to follow this  
Matthew Shockley

OpenGL OpenGL 2D

This topic is 2999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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);
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!