?? a2.cpp
字號:
#include <windows.h>
#include <gl/glut.h>
#include <stdlib.h>
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,1.0f);
//glRectf(-25.0f,25.0f,25.0f,-25.0f);
glBegin(GL_TRIANGLES);
glVertex2f(-100.0f,0.0f);
glVertex2f(-300.0f,200.0f);
glVertex2f(440.0f,200.0f);
glEnd();
glFlush();
}
void SetupRC(void)
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
}
void ChangeSize(GLsizei w,GLsizei h)
{
GLfloat aspectRatio;
glViewport(50,50,w/2,h/2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspectRatio=(GLfloat)w/(GLfloat)h;
if(w<=h)
glOrtho(-300.0,200.0,-200.0/aspectRatio,200.0/aspectRatio,1.0,-1.0);
else
glOrtho(-200.0*aspectRatio,200.0*aspectRatio,-200.0,200.0,1.0,-1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void processNormalKeys(unsigned char key,int x,int y)
{
if(key==27)
exit(0);
}
void main(void)
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutCreateWindow("glrect");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
SetupRC();
glutKeyboardFunc(processNormalKeys);
glutMainLoop();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -