gpt4 book ai didi

c - 在 openGL 中使用 glGenBuffers 时出现空白屏幕

转载 作者:行者123 更新时间:2023-11-30 19:43:38 24 4
gpt4 key购买 nike

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>

void changeSize(int w, int h)
{
if(h == 0)
h = 1;
float ratio = w / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(40,ratio,1.5,20);
glMatrixMode(GL_MODELVIEW);
}

void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT );
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glDrawArrays(GL_TRIANGLES,0,3);
glutSwapBuffers();
}

void init()
{
GLfloat verts[] = {
0.0, 1.0,
-1.0, -1.0,
1.0, -1.0
};

GLuint bufferid;
glGenBuffers(1,&bufferid);
glBindBuffer(GL_ARRAY_BUFFER,bufferid);
glBufferData(GL_ARRAY_BUFFER,sizeof(verts),verts,GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,0);

if(glGetError()==GL_NO_ERROR)
printf("no error");
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow("MM 2004-05");
glewInit();

init();

glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);

if (GLEW_ARB_vertex_program && GLEW_ARB_fragment_program)
printf("Ready for GLSL\n");
else {
printf("No GLSL support\n");
//exit(1);
}

glutMainLoop();
return 0;
}

当使用 glGenBuffers 时,我的屏幕变黑并且没有显示错误。如果我在不使用缓冲区的情况下绘制其他形状,它们会显示,但不会显示缓冲区对象。

openGL版本:3.0操作系统:ubuntuIDE:eclipse

最佳答案

当使用glGenBuffers时,您正在使用OpenGL-3.0规范。要在 OpenGL-3.0+ 中绘制任何内容,您需要使用着色器,因此屏幕是黑色的;你的三角形没有被遮蔽。

关于c - 在 openGL 中使用 glGenBuffers 时出现空白屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29426874/

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