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);
}
OpenGL 2D
I want to create a 2D game and display everything by pixels. Here is my code so far:
Bad thing is, it doesn't render anything on the screen. Can someone please explain to me what I am doing wrong?
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);}
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.
The z for the object has to be between 0 and 1, or alternatively, expand your near and far planes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement