2012-04-20 4 views
0

私はGLUTプログラムの例を実行しようとしていますが、白いウィンドウしか作成せずにアプリケーションをフリーズします。私はglutMainLoopを呼び出すときにフリーズしていました(glutCheckLoopをループで呼び出すと同じです)。私が紛失しているかもしれない何か?あなたはglutMainLoop()、仲間を配置したい場所をmac osxのglutMainLoop Lionがアプリケーションをフリーズする

#include <stdlib.h> 

#ifdef __APPLE__ 
#include <GLUT/glut.h> 
#else 
#include <GL/glut.h> 
#endif 

// Question 1: In a GLUT program, how is control passed 
// back to the programmer? How is this set up during 
// initialization? 

int win_width = 512; 
int win_height = 512; 

void display(void) 
{ 
    glClear(GL_COLOR_BUFFER_BIT); 

    glutSwapBuffers(); 
} 

void reshape(int w, int h) 
{ 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 

    // Question 3: What do the calls to glOrtho() 
    // and glViewport() accomplish? 
    glOrtho(0., 1., 0., 1., -1., 1.); 
    glViewport(0, 0, w, h); 

    win_width = w; 
    win_height = h; 

    glutPostRedisplay(); 
} 

void keyboard(unsigned char key, int x, int y) { 
    switch(key) { 
    case 27: // Escape key 
    exit(0); 
    break; 
    } 
} 

int main (int argc, char *argv[]) { 

    glutInit(&argc, argv); 
    // Question 2: What does the parameter to glutInitDisplayMode() 
    // specify? 
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 
    glutInitWindowSize(win_width, win_height); 

    glutCreateWindow("Intro Graphics Assignment 1"); 

    glutDisplayFunc(display); 
    glutReshapeFunc(reshape); 
    glutKeyboardFunc(keyboard); 

    glutMainLoop(); 
    return 0; 
} 

答えて

0

それは

+0

の色を見てください。あなたがそれを理解してうれしいです。 –

1

int型メインではありません。

はここで私が見つけたサンプルコードです。

これはinitメソッド、つまりinitGlutDisplay()にある必要があります。

#include <stdlib.h> 

#ifdef __APPLE__ 
#include <GLUT/glut.h> 
#else 
#include <GL/glut.h> 
#endif 

// Question 1: In a GLUT program, how is control passed 
// back to the programmer? How is this set up during 
// initialization? 

int win_width = 512; 
int win_height = 512; 


void display(void) 
{ 
    glClear(GL_COLOR_BUFFER_BIT); 

    glutSwapBuffers(); 
} 

void reshape(int w, int h) 
{ 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 

    // Question 3: What do the calls to glOrtho() 
    // and glViewport() accomplish? 
    glOrtho(0., 1., 0., 1., -1., 1.); 
    glViewport(0, 0, w, h); 

    win_width = w; 
    win_height = h; 

    glutPostRedisplay(); 
} 

void keyboard(unsigned char key, int x, int y) { 
    switch(key) { 
    case 27: // Escape key 
    exit(0); 
    break; 
    } 
} 
int initGlutDisplay(int argc, char* argv[]){ 
    glutInit(&argc, argv); 
    // Question 2: What does the parameter to glutInitDisplayMode() 
    // specify? 
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 
    glutInitWindowSize(win_width, win_height); 

    glutCreateWindow("Intro Graphics Assignment 1"); 

    glutDisplayFunc(display); 
    glutReshapeFunc(reshape); 
    glutKeyboardFunc(keyboard); 

    glutMainLoop(); 
    return 0; 
} 
int main (int argc, char *argv[]) { 
    int win_width = 512; 
    int win_height = 512; 
    initGlutDisplay(argc, argv); 

} 

上記のコードは完璧に動作するはずです。

EDIT

AGL opengl

によると、Cバインディングを持つ古い炭素ベースのAPIです。ウィンドウ処理とイベントハンドリングに必要なCarbonの部分 はスレッドセーフではありません。このAPIのバージョンは で、64ビット版はありません。

これが問題かどうかと思います。アップルがopengl Programming guideを確認して、問題を解決する可能性のある手順がないかどうかを確認します。

+0

(gccで動作するようになりました)コンパイラのバグだったあなたのコードを試してみました、それが働いた後、あなたは、元のコードを試してみましたが、それが失敗しましたか?私は同じフリーズ結果を得ているので – Inuart

+0

ええ、私のコードは完璧に働いた。興味深いことに、私もあなたのコードを試して、それは完全に働いた。 http://s13.postimage.org/rmq3psp7r/Screenshot_1.png –

+0

私の編集 –

関連する問題