reshape.cpp

학교/그래픽스 2013. 5. 3. 17:47


#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();

}

'학교 > 그래픽스' 카테고리의 다른 글

OPENGL 설치  (0) 2013.06.07
openGL 설치  (0) 2013.06.05
mouse.cpp  (0) 2013.05.03
그래픽스 실습  (0) 2013.04.12