您的位置:首页 > 理论基础

计算机图形学-课堂笔记1

2016-10-18 10:37 225 查看
一、【实践】配置OpenGL环境+测试

1.配置环境

下载glut工具包(下载链接-->http://download.csdn.net/detail/jinlin_23/9656597)   

文件放置位置如下图所示:

          


2.新建项目
点击VS菜单上的【文件】-->【新建】-->【项目】;

选择【Visual C++】 中的  【Win32控制台应用程序】 ;

填写项目名称和项目存放位置后,点击【确定】;

【下一步】-->勾选【空项目】-->【完成】;

    此时名为 ConsoleApplication2 的项目就创建好了。



对项目点右键-->【添加】-->【新建项】;

选择【Visual C++】-->【C++ 文件】;

编辑此文件名称后,点击【添加】;

即可添加名为【源.cpp】的文件。



3.运行测试

在【源.cpp】的文件中添加以下代码进行测试

// Simple OpenGl program which draws a red sphere in a white window of 500x500 size.
#include

void my_display (void)
{
glClearColor(1, 1, 1, 0);		// Specify the background color used when the color buffers are cleared. Default: all 0s
glClear(GL_COLOR_BUFFER_BIT);	// Clear buffers to preset values
glColor3f(1.0, 0.0, 0.0);		// Specify the color used to draw objects
glutSolidSphere(0.5, 50, 40);	// Draw a sphere centerred at the origin, where the 3 parameters are: radius, slices, & stacks
glFlush();
//若运行不成功可尝试注释掉glFlush();并添加glutSwapBuffers();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//若运行不成功可尝试将其中GLUT_SINGLE改为GLUT_DOUBLE
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("A red sphere in a white window");
glutDisplayFunc(my_display);
glutMainLoop();
return 0;
}

运行结果为:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenGL 图形学