2011-12-11 2 views
1

C++에서 OpenGL을 시작, 지금까지 다음과 같은 코드가하기 : 그것은 모두 잘 컴파일,내가 <a href="http://www.swiftless.com/tutorials/opengl/window.html" rel="nofollow">this tutorial</a>을 사용하여 OpenGL을 함께 프로그래밍을 시작하려고했습니다

#include <gl/glut.h> // Include the GLUT header file 

void display (void) 
{ 
} 

int main(int argc, char **argv) 
{ 
    glutInit(&argc, argv); // Initialize GLUT 
    // Set up a basic display buffer (only single buffered for now) 
    glutInitDisplayMode (GLUT_SINGLE); 
    glutInitWindowSize (500, 500); // Set the width and height of the window 
    glutInitWindowPosition (100, 100); // Set the position of the window 
    // Set the title for the window 
    glutCreateWindow("Your first OpenGL Window!"); 

    glutDisplayFunc(display); 
    glutMainLoop(); 
    glClearColor(1.f, 0.f, 0.f, 1.f); // Clear the background of our window to red 

    return 0; 
} 

내가 빌드 이클립스에서 프로젝트를 실행하지만, 아무 일도 일어나지 않습니다 (아무 창이 나올 수 없습니다). 아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까?

+0

코드가 실제로 실행 중인지 확인하려면 print 문을 추가하십시오. – Lalaland

답변

1
glutInitDisplayMode (GLUT_SINGLE); 

는 또한 적어도 (그리고 아마도 깊이 버퍼를 원하는)하는 GLUT_RGBA를 추가, 즉 당신이 원하는 프레임 버퍼 형식의 종류를 정의해야합니다. 그리고 이중 버퍼를 원하지 않는 경우는 드물다. 그래서 : 당신이glutCreateWindowglutDisplayFunc(display);을 추가하지 않으면

glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);는 그런 다음 표시 기능, 호출되지 않습니다.

glutMainLoop(); 
glClearColor(1.f, 0.f, 0.f, 1.f); 

glutMainLoop이 반환되지 않습니다. 그리고 그랬더라도 glClearColor는 프로그램의 해당 위치에서 효과가 없습니다.

관련 문제