使用opengl编译的程序,但不';跑不动

使用opengl编译的程序,但不';跑不动,opengl,codeblocks,Opengl,Codeblocks,我想要opengl for code::blocks,并使用下面的链接进行设置: 我尝试了示例文件: #include <iostream> #include <GL/glut.h> using namespace std; GLfloat mat_ambient[] = {0.5, 0.5, 0.5, 1.0}; GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat_shininess[] = {50

我想要opengl for code::blocks,并使用下面的链接进行设置:

我尝试了示例文件:

#include <iostream>
#include <GL/glut.h>

using namespace std;

GLfloat mat_ambient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[] = {50.0};
GLfloat light_position[] = {10.0, 10.0, 10.0, 0.0};
GLfloat model_ambient[] = {1.0, 0.5, 0.5, 1.0};

void setupMaterials() {
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
}

void changeColour(GLfloat r, GLfloat g, GLfloat b, GLfloat A) {
    model_ambient[0] = r;
    model_ambient[1] = g;
    model_ambient[2] = b;
    model_ambient[3] = A;
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
}

void init(void) {
    glClearColor(0.0, 0.0, 0.0, 1.0);
    setupMaterials();

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glFrontFace(GL_CCW);
    glShadeModel(GL_SMOOTH);
}

void reshape(int w, int h) {
    GLfloat fAspect;
    if(h==0) h=1;

    glViewport(0,0,w,h);

    fAspect = (GLfloat)w / (GLfloat)h;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(60, fAspect, 0.5, 100.0);
    glTranslatef(0,0,-1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void display(void) {
    int slices = 30;
    int stacks = 30;
    float radius = 0.2;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    changeColour(0.0, 0.0, 1.0, 1.0);
    glTranslatef(0.0, 0.0, 0.1);
    glutSolidSphere(radius, slices, stacks);
    glPopMatrix();

    glFlush();
    glutSwapBuffers();
}

void keyboard(unsigned char key, int x, int y) {
    switch (key) {
        case 27:
            exit(0); // Exit the application if 'Esc' key is pressed
    }
}

void animate() {
    glutPostRedisplay();
}

int main(int argc, char * argv[]) {
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize (800, 600);
    glutCreateWindow (argv[0]);   init();
    glutKeyboardFunc (keyboard);
    glutDisplayFunc (display);
    glutReshapeFunc (reshape);
    glutIdleFunc(animate);
    glutMainLoop();
    return 0;
}
#包括
#包括
使用名称空间std;
GLfloat mat_环境[]={0.5,0.5,0.5,1.0};
GLfloat mat_镜面反射[]={1.0,1.0,1.0,1.0};
GLfloat mat_亮度[]={50.0};
GLfloat light_位置[]={10.0,10.0,10.0,0.0};
GLfloat模型_环境[]={1.0,0.5,0.5,1.0};
无效材料(){
GLMATERIALV(GL_前部、GL_环境、mat_环境);
GLMATERIALV(GL_前部、GL_镜面反射、mat_镜面反射);
GLMATERIALV(GL_正面、GL_反光、mat_反光);
glLightfv(GLU灯0、GLU位置、灯位置);
glLightModelfv(GL_灯光_模型_环境光,模型_环境光);
}
空隙变色(GLfloat r、GLfloat g、GLfloat b、GLfloat A){
模型_环境[0]=r;
模型_环境[1]=g;
模型_环境[2]=b;
模型_环境[3]=A;
glLightModelfv(GL_灯光_模型_环境光,模型_环境光);
}
void init(void){
glClearColor(0.0,0.0,0.0,1.0);
设置材料();
glEnable(德国劳埃德大学照明);
glEnable(GL_LIGHT0);
glEnable(GLU深度试验);
glEnable(GL_CULL_面);
glFrontFace(GL_CCW);
glShadeModel(GL_平滑);
}
空洞重塑(整数w,整数h){
glfaspect;
如果(h==0)h=1;
glViewport(0,0,w,h);
fAspect=(GLfloat)w/(GLfloat)h;
glMatrixMode(GL_投影);
glLoadIdentity();
gluPerspective(60,fAspect,0.5100.0);
glTranslatef(0,0,-1);
glMatrixMode(GLU模型视图);
glLoadIdentity();
}
作废显示(作废){
int切片=30;
int=30;
浮动半径=0.2;
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
glPushMatrix();
变色(0.0,0.0,1.0,1.0);
glTranslatef(0.0,0.0,0.1);
实心球体(半径、切片、堆栈);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
无效键盘(无符号字符键,整数x,整数y){
开关(钥匙){
案例27:
退出(0);//如果按下“Esc”键,则退出应用程序
}
}
void animate(){
再发现();
}
int main(int argc,char*argv[]){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_双精度| GLUT_RGB | GLUT_深度);
glutInitWindowSize(800600);
glutCreateWindow(argv[0]);init();
键盘Func(键盘);
glutDisplayFunc(显示器);
GLUTREFORUNC(重塑);
glutIdleFunc(动画);
glutMainLoop();
返回0;
}
编译没有问题,但每次尝试运行它时,我都会得到:

进程终止,状态为-1073741515(0分钟2秒)

我已经发现这是由线路引起的:

#include <GL/glut.h>
#包括

但我不明白为什么会这样。有人能帮我吗?

我使用Windows7,我提到的网站特别声明“如果您使用的是64位Windows 7,您需要将此文件复制到'C:\Windows\sysWOW64'中”,我没有这样做。当我做对这一步时,我让程序运行了

帮我拍一下那个网站的作者。永远不要把DLL放在操作系统路径中,这会让其他也使用DLL但希望使用不同版本的程序很混乱。相反,只需将DLL放在与.exe相同的目录中(或者,如果通过Visual Studio调试器运行它,请将DLL的副本放在项目目录中)。