注册 登录
编程论坛 C图形专区

画个多边形

qq1023569223 发布于 2011-04-21 08:45, 1126 次点击
程序代码:
#include <GL/glut.h>

void Draw_Polygon(void)
{
    glColor3f(1.0,0.0,0.0);

    glBegin(GL_POLYGON);
    glVertex2i(0,250);
    glVertex2i(250,0);
    glVertex2i(500,250);
    glVertex2i(250,500);
    glEnd();

    glFlush();
}

void main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(600,600);
    glutCreateWindow("0810050225");

    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0.0,500.0,0.0,500.0);

    glutDisplayFunc(Draw_Polygon);
    glutMainLoop();
}
只有本站会员才能查看附件,请 登录
14 回复
#2
qq10235692232011-04-21 19:05
对于刚开始学OpenGL的同学来说,上面的程序是一个模板,main函数部分是一个通式!
#3
songkun1232011-04-29 17:14
#include <GL/glut.h>
怎么弄呀?
#4
qq10235692232011-04-29 19:19
下个软件包,然后再装啊!
#5
qq10235692232011-04-29 19:20
With thanks to Kamil Saykali of the EdCenter:

This part will show how to install the glut libraries and dll's (to download it go to http://reality. )

1. After you have downloaded the glut.zip file (you should get the latest ver 3.7) unzip it into a folder

2. Inside the folder you should have:

glut.dll

glut32.dll

glut.h

glut.lib

glut32.lib

3. Copy both glut.dll and glut32.dll into your windows directory (windows or winnt, depends on if you are using Windows95/98 or Windows NT)

4. Copy your glut.h to:

<drive>:\<VC++ path>\include\GL\glut.h

*** put the drive where you installed VC++ instead of the <drive> ***

*** put the directory where you installed VC++ instead of the <VC++ path>

5. Copy your glut.lib and glut32.lib to:

<drive>:\<VC++ path>\lib\glut.lib

<drive>:\<VC++ path>\lib\glut32.lib

*** put the drive where you installed VC++ instead of the <drive> ***

*** put the directory where you installed VC++ instead of the <VC++ path>

6. That should be it for installed the glut libraries. The rest of this letter shows you how to setup VC++ so that you can use the glut libraries.

This will show you how to start up an opengl project and setup the setting so that you will be able to compile and run the program. This is assuming that you have already downloaded the appropriate files and installed them in the directories that there documentation tell you to. If you have not done that you need to do it before you can run or write an opengl program.

1. Start VC++ and create a new project.

2. The project has to be a "Win32 Console Application"

3. Type in the name of the project and where it will be on your hard drive.

4. Chose an empty project and click next or finish

5. First thing you need to do when the project opens up is to click on the "Project" menu item from the top.

6. Chose "Settings" (a window will come up)

7. On the left side of the window there are tabs, chose the "Link" tab

8. The string field labeled "Object/library modules" has a few lib files already set in it

9. Go to the end of this string field and enter:

opengl32.lib glut32.lib glu32.lib

10. Chose "OK" and that will include all the opengl libraries that you need

11. Now all you need to do is include <gl\glut.h> and you are ready to go
只有本站会员才能查看附件,请 登录
#6
mybluedesky2011-05-14 10:25
,就是这个
#7
mybluedesky2011-05-16 11:43
画出来了,
#8
qq10235692232011-05-16 11:45
那就好呵!
#9
墨竹2011-05-17 11:05
Linking...
LINK : fatal error LNK1104: cannot open file "glut32.lib"
Error executing link.exe.
怎么回事?
#10
墨竹2011-05-17 11:08
呃...
没问题了,路径放错了
#11
墨竹2011-05-17 11:11
那两个dll文件是不是必须跟程序源文件放在一起啊?
#12
qq10235692232011-05-18 19:23
呵,注意了!
#13
qq10235692232011-05-18 19:24
不要,放在系统文件夹里就可以了!程序会自动去找!这也是所谓的dll组件共享!

[ 本帖最后由 qq1023569223 于 2011-5-18 19:25 编辑 ]
#14
墨竹2011-05-19 16:05
回复 13楼 qq1023569223
嗯,谢谢了
#15
zhangxiajun2011-07-06 15:21
只有本站会员才能查看附件,请 登录

我的电脑上编译出来怎么是这个样子啊?
我的软件环境是:windows xp sp3 + vc++ 6.0 sp6
硬件环境是:E5800 + 2G + intelG41集成显卡
1