Dev-C++中OpenGL
网上所有的资料搜遍了,别人说行了,可用到我这儿哪个都不好使。
OpenGL红宝书里说#include <GL/glut.h>就够了,可是网上说#include <GL/gl.h>和#include <GL/glu.h>也得有,说自己没包含这两个的时候不行,一包含就行了,不知道为什么。我也跟着做了,还是不行。
网上说glut.lib放lib文件夹里。我放了。网上说glut.dll放windows\system32里,我放了。网上说glut.h放\include\GL\里,我放了,还是不行。
网上说得定义宏#define GLUT_DISABLE_ATEXIT_HACK,我做了,还是不行。
台湾网页里说,得下载安装Dev-C++的glut包,我下了安了,还是不行。
有人在VC里成功了。我特别不想用VC,想用DEV,但还是极不情愿地去VC里编译,还是不行。
每次的出错提示大概都是 [Linker error] undefined reference to `glutInit'
之类。
我都快疯了。高人帮忙~
以下贴出我的源代码:
#define GLUT_DISABLE_ATEXIT_HACK
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
//#include <windows.h>
void display(void);
void init(void);
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindoPosition(100, 100);
glutCreateWindow("hello");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glEnd();
glFlush();
}
void init(void){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}