Sign in to follow this  
Matthew Shockley

OpenGL OpenGL 2D

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);
	//gluPerspective(45.0, aspect, 1.0, 100.0);
    glOrtho(0, Width, Height, 0, 0, 1);
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
Here you go:

void DrawGraphics()
glTranslated(0, 0, -10);
glColor3d(1, 0, 0);
glVertex3d(10, 20, 0);
glVertex3d(15, 20, 0);
glVertex3d(20, 25, 0);

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this