2015-02-06 56 views
-1

我需要繪製一個立方體來指示座標在OpenGL 3.3核心profile.It工作正常,沒有glutInitContextVersion (3, 3);但它變得全黑時應用glutInitContextVersion (3, 3);。 這是繪圖代碼。glbegin沒有繪製在OpenGL 3.3核心

void display() { 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers 
glMatrixMode(GL_MODELVIEW);  // To operate on model-view matrix 

// Render a color-cube consisting of 6 quads with different colors 
glLoadIdentity();     // Reset the model-view matrix 
glTranslatef(1.5f, 0.0f, -7.0f); // Move right and into the screen 

glBegin(GL_QUADS);    // Begin drawing the color cube with 6 quads 
    // Top face (y = 1.0f) 
    // Define vertices in counter-clockwise (CCW) order with normal pointing out 
    glColor3f(0.0f, 1.0f, 0.0f);  // Green 
    glVertex3f(1.0f, 1.0f, -1.0f); 
    glVertex3f(-1.0f, 1.0f, -1.0f); 
    glVertex3f(-1.0f, 1.0f, 1.0f); 
    glVertex3f(1.0f, 1.0f, 1.0f); 

    // Bottom face (y = -1.0f) 
    glColor3f(1.0f, 0.5f, 0.0f);  // Orange 
    glVertex3f(1.0f, -1.0f, 1.0f); 
    glVertex3f(-1.0f, -1.0f, 1.0f); 
    glVertex3f(-1.0f, -1.0f, -1.0f); 
    glVertex3f(1.0f, -1.0f, -1.0f); 

    // Front face (z = 1.0f) 
    glColor3f(1.0f, 0.0f, 0.0f);  // Red 
    glVertex3f(1.0f, 1.0f, 1.0f); 
    glVertex3f(-1.0f, 1.0f, 1.0f); 
    glVertex3f(-1.0f, -1.0f, 1.0f); 
    glVertex3f(1.0f, -1.0f, 1.0f); 

    // Back face (z = -1.0f) 
    glColor3f(1.0f, 1.0f, 0.0f);  // Yellow 
    glVertex3f(1.0f, -1.0f, -1.0f); 
    glVertex3f(-1.0f, -1.0f, -1.0f); 
    glVertex3f(-1.0f, 1.0f, -1.0f); 
    glVertex3f(1.0f, 1.0f, -1.0f); 

    // Left face (x = -1.0f) 
    glColor3f(0.0f, 0.0f, 1.0f);  // Blue 
    glVertex3f(-1.0f, 1.0f, 1.0f); 
    glVertex3f(-1.0f, 1.0f, -1.0f); 
    glVertex3f(-1.0f, -1.0f, -1.0f); 
    glVertex3f(-1.0f, -1.0f, 1.0f); 

    // Right face (x = 1.0f) 
    glColor3f(1.0f, 0.0f, 1.0f);  // Magenta 
    glVertex3f(1.0f, 1.0f, -1.0f); 
    glVertex3f(1.0f, 1.0f, 1.0f); 
    glVertex3f(1.0f, -1.0f, 1.0f); 
    glVertex3f(1.0f, -1.0f, -1.0f); 
glEnd(); // End of drawing color-cube 


glutSwapBuffers(); // Swap the front and back frame buffers (double buffering) 
} 

這裏是主函數的代碼:

int main(int argc, char** argv) { 
glutInit(&argc, argv);   // Initialize GLUT 
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); // Enable double buffered mode 
glutInitContextVersion (3, 3); 
glutInitWindowSize(640, 480); // Set the window's initial width & height 
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner 
glutCreateWindow(title);   // Create window with the given title 
glutDisplayFunc(display);  // Register callback handler for window re-paint event 
glutReshapeFunc(reshape);  // Register callback handler for window re-size event 
initGL();      // Our own OpenGL initialization 
glutMainLoop();     // Enter the infinite event-processing loop 
return 0; 
} 

如何畫一個立方體在OpenGL 3.3核心配置文件?

+0

我認爲固定功能的東西在OpenGL 3.x之後被移除了?我想,您需要切換到較早版本的OpenGL或使用着色器。 **編輯:**請參閱[此問題](http://stackoverflow.com/questions/6573398/list-of-deprecated-opengl-functionalities)以獲取更多信息。 – GoBusto 2015-02-06 08:50:04

回答

5

gBegin和朋友已棄用並從新版本(3.2版以後)中刪除。

相反,您需要將頂點數據上傳到頂點緩衝區對象。然後使用glVertexAttribPointer來告訴openGL數據是如何佈局的。

除此之外,您需要編寫着色器。

2

固定功能管道(glVertex,glBegin等)在Core Profile中不存在。