opengl vs2005程序

来源:百度知道 编辑:UC知道 时间:2024/06/01 06:30:40
#include <windows.h> // use as needed for your system
#include <gl\Gl.h>
#include <gl\glut.h>

#pragma comment(linker, "/subsystem:\"windows\" \
/entry:\"mainCRTStartup\"")
class GLintPoint
{
public:
GLint x,y;
};
int random (int x)
{
return rand () % x;
}
void drawDot (GLint x, GLint y)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void Sierpinski(void)
{
GLintPoint T[3]= {{10,10},{300,30},{200, 300}};

int index = random(3); // 0, 1, or 2 equally likely
GLintPoint point = T[index]; // initial point
drawDot(point.x, point.y); // draw initial point
for(int i = 0; i < 1000; i++) // draw 1000 dots
{
index = random(3);
point.x = (point.x + T[index].x) / 2;
point.y = (point.y + T[index].y) / 2;
drawDot(po

glut.lib, glut32.lib 放到<VCDIR>\PlatformSDK\lib
glut.h 放到<VCDIR>\PlatformSDK\include\gl
glut.dll, glut32.dll 放入<system32>

对你下面这行,
#pragma comment(linker, "/subsystem:\"windows\" \
/entry:\"mainCRTStartup\"")

好像在window\"\后面有一个非unicode字符(这是一个空格), 你把这一行直接写为:

#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") ,注意删掉/entry之前的\

生成、运行看, 我直接复制你的代码, 得到一个背景色透明的,点阵图。

另外, <GL/glut.h>中已经包含有<GL/gl.h>, #include <gl\Gl.h>可以不用写。

good luck!