검색결과 리스트
글
reshape.cpp
#include<GL/glut.h>
#include<stdlib.h>
void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.5,0.5,0.5);
glBegin(GL_POLYGON);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,-0.5,0.0);
glVertex3f(0.5,0.5,0.0);
glVertex3f(-0.5,0.5,0.0);
glEnd();
glFlush();
}
void MyKeyboard(unsigned char key, int x, int y)
{
if(key=='Q')
{
exit(0);
}
else if(key=='q')
{
exit(0);
}
else if(key==27)
{
exit(0);
}
}
void MyReshape(int width,int height)
{
glViewport(0,0,width,height);
GLfloat widthFactor=(GLfloat)width/(GLfloat)300;
GLfloat heightFctor = (GLfloat)width/(GLfloat)300;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0*widthFactor,1.0*widthFactor,-1.0*heightFctor,1.0*heightFctor,-1.0,1.0);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(300,300);
glutInitWindowPosition(0,0);
glutCreateWindow("Reshape Test");
glClearColor(1.0,1.0,1.0,1.0);
glutDisplayFunc(MyDisplay);
glutReshapeFunc(MyReshape);
glutKeyboardFunc(MyKeyboard);
glutMainLoop();
}