上一篇博文发了OpenGL中一些绘制图形函数的区别并且给出了在同一组数据下不同函数显示的不同效果图,博文地址为:http://www.5dkx.com/arch/138.html。
在这篇文章里,给出实现上一篇博文的OpenGL具体程序代码
下面就是程序清单
// triangle.cpp : 定义控制台应用程序的入口点。
//
/*
FILE:huizhi.cpp
DONE:使用OpenGL绘制几何图形
author:www.5dkx.com
date:2010-3-18
*/
#include "windows.h"
#include "gl/gl.h"
#include "gl/glaux.h"
#include "gl/glu.h"#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glaux.lib")
#pragma comment(lib,"glu32.lib");void MyInit();
void CALLBACK MyReshape(GLsizei w,GLsizei h);
void MyDraw();
void CALLBACK MyDisplay();
int main()
{MyInit();
auxReshapeFunc(MyReshape);
auxMainLoop(MyDisplay);
return 0;
}
void MyInit()
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
auxInitPosition(100,100,500,500);
auxInitWindowA("测试");
glClearColor(0.,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
}
void CALLBACK MyReshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
void CALLBACK MyDisplay()
{
glClearColor(0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
MyDraw();
glFlush();
}void MyDraw()
{
GLfloat Vertex[][2] = {{-0.0,0.8},{0.5,0.8},{0.75,0.0},{0.5,-0.5}};
glBegin(GL_TRIANGLE_STRIP);// 在这里替换不通的OpenGL绘制几何图形函数
glVertex2f(-0.5,0.0);
glVertex2f(-0.4,0.5);
for(int i=0;i<4;i++)
{
//glColor3f(0.1,GLfloat(i/10),0.1);
glVertex2fv(Vertex[i]);
//Sleep(5000);
}
glEnd();
}
首发:http://www.5dkx.com/arch/139.html
非特别说明均为原创文章如转载,请注明:转载自 5D开心博客 [ http://www.5DKX.com/ ]