gpt4 book ai didi

c - OpenGL 3.3 不会绘制我的三角形

转载 作者:行者123 更新时间:2023-12-01 23:41:53 24 4
gpt4 key购买 nike

我正在使用 C 而不是 C++ 来学习这些教程: Tutorial 2 , short extension to tutorial 2 .

我对它进行移植的唯一更改是将 Vector3f[3] 更改为 GLfloat[9]。使用 GLfloat[1] 而不是 Vector3f[1] 的版本可以正常工作。我认为此更改可能是 glDrawArrays 无法正常工作的原因,但我不知道如何修复它。

#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>

GLuint VBO_id;

static void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);

glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO_id);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

glDrawArrays(GL_TRIANGLES, 0, 3);

glDisableVertexAttribArray(0);

glutSwapBuffers();
}

static void CreateVertexBuffer()
{
GLfloat Vertices[9] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f,
1.0f, 0.0f };

glGenBuffers(1, &VBO_id);
glBindBuffer(GL_ARRAY_BUFFER, VBO_id);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices,
GL_STATIC_DRAW);
}


int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(600, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 03");
glutDisplayFunc(RenderSceneCB);

GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
return 1;
}

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateVertexBuffer();
glutMainLoop();

return 0;
}

最佳答案

来自here .

OpenGL 3.0 was the last revision of the specification which fully supported both fixed and programmable functionality. Even so, most hardware since the OpenGL 2.0 generation lacked the actual fixed-function hardware. Instead, fixed-function processes are emulated with shaders built by the system.

In OpenGL 3.2, the Core Profile lacks these fixed-function concepts. The compatibility profile keeps them around. However, most newer features of OpenGL cannot work with fixed function, even when it might seem theoretically possible for them to interact.

听起来您的 OpenGL 版本不支持固定功能管道。要么使用旧版本的 OpenGL,要么编写并加载着色器,如 Tutorial 4 所示。 .

关于c - OpenGL 3.3 不会绘制我的三角形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32425421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com