OpenGL的一个测试例子

作者在 2010-04-17 14:21:18 发布以下内容

#include "windows.h"
#include "gl/gl.h"
#include "gl/glaux.h"
#include "gl/glu.h"

void myinit(void);
void InitPalette(void);
void DrawColorFans(void);
void CALLBACK myReshape(GLsizei w,GLsizei h);
void CALLBACK display(void);

void myinit(void)
{
 glClearColor(0.0,0.0,0.0,0.0);
 glClear(GL_COLOR_BUFFER_BIT);
 glShadeModel(GL_FLAT);
}

void InitPalette(void)
{
 GLint j;
 static GLfloat rgb[][3]={
 {1.0,0.0,0.0},{1.0,0.0,0.5},{1.0,0.0,1.0},{0.0,0.0,1.0},
 {0.0,1.0,1.0},{0.0,1.0,0.0},{1.0,1.0,0.0},{1.0,0.5,0.0}};

for(j=0;j<8;j++)
 auxSetOneColor(j+1,rgb[j][0],rgb[j][1],rgb[j][2]);
}

void CALLBACK myReshape(GLsizei w,GLsizei h)
{
 glViewport(0,0,w,h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 if(w<=h)
 glOrtho(-12.0,12.0,-12.0*(GLfloat)h/(GLfloat)w, 12.0*(GLfloat)h/(GLfloat)w,-30.0,30.0);
 else
 glOrtho(-12.0*(GLfloat)h/(GLfloat)w, 12.0*(GLfloat)h/(GLfloat)w,-12.0,12.0,-30.0,30.0);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
}

void CALLBACK display(void)
{
 InitPalette();
 DrawColorFans();
 glFlush();
}

void DrawColorFans(void)
{
 GLint n;
 GLfloat pp[8][2]={
 {7.0,-7.0},{0.0,-10.0},{-7.0,-7.0},{-10.0,0.0},
 {-7.0,7.0}, {0.0,10.0},{7.0,7.0},{10.0,0.0}};

 /* draw some filled_fan_triangles */
 glBegin(GL_TRIANGLE_FAN);
 glVertex2f(0.0,0.0);
 glVertex2f(10.0,0.0);
 for(n=0;n<8;n++)
 {
 glIndexi(n+1);
 glVertex2fv(pp[n]);
 }
 glEnd();
}

void main(void)
{
 auxInitDisplayMode(AUX_SINGLE|AUX_INDEX);
 auxInitPosition(0,0,500,500);
 auxInitWindow("Color Index");
 myinit();
 auxReshapeFunc(myReshape);
 auxMainLoop(display);
}

注:进入“Project”菜单,选择“Setting”项,弹出“Project Setting”对话框,选择“Link”项,在“Libaray”栏目中加入OpenGL提供的函数库:“opengl32.lib glu32.lib glaux.lib”。

默认分类 | 阅读 940 次
文章评论,共0条
游客请输入验证码
浏览46498次
文章分类