在VS2012下使用glut来建一个窗口,使用的是Win32控制台程序,演示效果如下所示:
源代码如下:
#include "stdafx.h"
#include <gl/glut.h>
//获取屏幕的宽度
GLint SCREEN_WIDTH=0;
GLint SCREEN_HEIGHT=0;
//设置程序的窗口大小
GLint windowWidth=400;
GLint windowHeight=300;
//显示回调函数
void renderScreen(void){
//把整个窗口清理为当前清理颜色:南瓜橙
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
//设置Redering State
void setupRederingState(void){
//设置清理颜色为南瓜橙
glClearColor(0.98f,0.625f,0.12f,1.0f);
}
int main(int argc, char* argv[])
{
//初始化glut
glutInit(&argc,argv);
//单缓冲区
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
//获取系统的宽像素
SCREEN_WIDTH=glutGet(GLUT_SCREEN_WIDTH);
//获取系统的高像素
SCREEN_HEIGHT=glutGet(GLUT_SCREEN_HEIGHT);
//创建窗口,窗口名字为WindowDemo
glutCreateWindow("WindowDemo");
//设置窗口大小
glutReshapeWindow(windowWidth,windowHeight);
//窗口居中显示
glutPositionWindow((SCREEN_WIDTH-windowWidth)/2,(SCREEN_HEIGHT-windowHeight)/2);
printf("SCREEN_WIDTH=%d\n\
SCREEN_HEIGHT=%d\n\
windowWidth=%d\n\
windowHeight=%d\n\
",SCREEN_WIDTH,SCREEN_HEIGHT,windowWidth,windowHeight);
//设置显示回调函数
glutDisplayFunc(renderScreen);
//设置全局渲染参数
setupRederingState();
glutMainLoop();
return 0;
}