glbegin不';在OpenGL 3.3内核中绘制

glbegin不';在OpenGL 3.3内核中绘制,opengl,Opengl,我需要画一个立方体来表示OpenGL 3.3核心配置文件中的坐标。它在没有glutInitContextVersion(3,3)的情况下运行良好但当glutInitContextVersion(3,3)时,它会变成完全黑色已应用。 这是图纸代码 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers glMatrixMode(GL_MODELVIEW

我需要画一个立方体来表示OpenGL 3.3核心配置文件中的坐标。它在没有
glutInitContextVersion(3,3)的情况下运行良好但当
glutInitContextVersion(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核心配置文件中绘制多维数据集?

核心配置文件中不存在固定功能管道(glVertex、glBegin等)。

glBegin和friends已弃用,并已从较新版本(3.2以后)中删除

相反,您需要将顶点数据上载到顶点缓冲区对象。然后使用glvertexattributepointer告诉openGL数据是如何布局的


除此之外,您还需要编写着色器。

我以为OpenGL 3.x以后的版本中删除了固定功能的东西?我认为,您需要切换到OpenGL的早期版本或使用着色器。编辑:有关详细信息,请参见。