使用opengl的程序可以编译,但是无法运行 [英] Program with opengl compiles, but doesn't run

查看:65
本文介绍了使用opengl的程序可以编译,但是无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要opengl作为code :: blocks并使用下面的链接进行设置: http://www.deannicholls.co.uk/tutorials/show/cpp_glut

I wanted opengl for code::blocks and used the link below to set it up: http://www.deannicholls.co.uk/tutorials/show/cpp_glut

我尝试了示例文件:

#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;
}

编译没有问题,但是每次我尝试运行它,我都会得到:

Compiling goes without problems, but everytime I try to run it I get:

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

"Process terminated with status -1073741515 (0 minute(s), 2 second(s))"

我已经发现这是由以下行引起的:

I already figured out that it's caused by the line:

#include <GL/glut.h>

但是我不知道为什么会导致这种情况.有人可以帮我吗?

But I could not figure out why it's causing this. Can someone help me out?

推荐答案

我使用Windows7,我提到的网站特别指出:如果您使用的是64位Windows 7,则需要将此文件复制到'C:\ Windows \ sysWOW64",我没有.当我正确执行该步骤后,我就可以运行该程序!

I use Windows7 and the site I mentioned specifically stated "If you're using Windows 7 64-bit, you'll need to copy this file into 'C:\Windows\sysWOW64", which I didn't. When I did that step right I got the program to run!

这篇关于使用opengl的程序可以编译,但是无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆