#include <Windows.h>
#define GLUT_DISABLE_ATEXIT_HACK
#include <glut.h>
#pragma comment("glut.lib", lib)
#pragma comment("OPENGL32.lib", lib)
void draw()
{
glClearColor(1.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 0);
glBegin(GL_POLYGON);
glVertex2f(0.25, 0.25);
glVertex2f(0.25, 0.75);
glVertex2f(0.75, 0.75);
glVertex2f(0.75, 0.25);
glEnd();
glFlush();
}
void Init()
{
glClearColor(1.0, 0.0, 0.0, 0.0);
//glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
void main(int argcp, char **argv)
{
glutInit(&argcp, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(800, 600);
glutCreateWindow("hello");
Init();
glutDisplayFunc(draw);
glutMainLoop();
return;
}
在 windows 平台中 通过 下面代码获取对 WGL函数的访问:
#include <windows.h>
glutInit(int argcp, char **argv) 应该在调用其他任何Glut函数之前调用
glutInitDisplayMode() 指定显示模式
GLUT_RGB 0
GLUT_RGBA GLUT_RGB
GLUT_INDEX 1
GLUT_SINGLE 0
GLUT_DOUBLE 2
GLUT_ACCUM 4
GLUT_ALPHA 8
GLUT_DEPTH 16
GLUT_STENCIL 32