PDA

View Full Version : How to draw a screen aligned QUAD?



apapaxionga
11-15-2011, 08:00 PM
if i initialize the Viewport like this:


glViewport(0, 0, screenWidth, screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, (float)(screenWidth)/screenHeight, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);

mobeen
11-16-2011, 12:17 AM
Hi,
You will need to use the orthographic projection for this. Something along these lines should work.


void OnResize(int nw, int nh) {
glViewport(0,0,nw,nh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,1,0,1,0,1);
glMatrixMode(GL_MODELVIEW);
}

Then use this code to draw the quad

void DrawFullScreen() {
glBegin(GL_QUADS);
glVertex2f(0,0);
glVertex2f(1,0);
glVertex2f(1,1);
glVertex2f(0,1);
glEnd();
}

See if this helps.

V-man
11-16-2011, 05:46 AM
Here's another one



void OnResize(int nw, int nh) {
glViewport(0,0,nw,nh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}




void DrawFullScreen() {
glBegin(GL_QUADS);
glVertex2f(-1,-1);
glVertex2f(1,-1);
glVertex2f(1,1);
glVertex2f(-1,1);
glEnd();
}