PDA

View Full Version : Doubt with reshape function



anoop4real
07-31-2011, 08:00 AM
Hi,

As per my understanding, reshape function of GLUT is used to adjust your drawing when the window is resized, is that a mandatory requirement for every drawing. When I tried the below code, it didnt gave me any output. I wasnt sure what the problem was, I was trying to learn a sample from one book, I then copied the reshape function and it started working fine. I am not sure why this was happening. Pls help, the below is the code which I tried to run with out reshape function



#include <stdlib.h>
#include <GLUT/glut.h>
#include <math.h>


void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1, 1, 0);
glPointSize(1.0);
glBegin(GL_POINTS);
glVertex3f(10.0f, 10.0f, 0.0f);
glVertex3f(20.0f, 10.0f, 0.0f);
glVertex3f(30.0f, 10.0f, 0.0f);
glVertex3f(40.0f, 10.0f, 0.0f);
glVertex3f(50.0f, 10.0f, 0.0f);
glVertex3f(60.0f, 10.0f, 0.0f);
glEnd();

glutSwapBuffers();
}


int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(0,0);
glutInitWindowSize(640, 480);

glutCreateWindow("GLUT Program");

glutDisplayFunc(display);


glutMainLoop();
return EXIT_SUCCESS;
}



-anoop

anoop4real
08-04-2011, 05:03 AM
Any help??

kowal
08-04-2011, 02:48 PM
You did not set the viewport (reshape func should do that)

glViewport(0,0, width, height) or something like that is needed to tell OpenGL where to draw.

Reshape function is called on every window resize and during window creation.