gpt4 book ai didi

c++ - 在 Linux 上使用 Qt 5.4 的某些 OpenGL 函数...

转载 作者:太空宇宙 更新时间:2023-11-04 03:46:31 25 4
gpt4 key购买 nike

下面的代码块适用于 Windows(在 VC++ 2013 中),因为我已经包含了 GL/glew.h,但在 Linux 上使用 QT Creator 时,它取消了包含的定义,因此下面粗体显示的函数不可用。

如何才能像在 Windows 下一样在 Linux 下使用 OpenGL 函数 glGetUniformBlockIndex()glUniformBlockBinding()glBindBufferBase()

感谢您的宝贵时间。

void QTOpenGLWindow::loadShaderUniforms() {

glUseProgram(MainOpenGLShaderProgramID);

MatricesUniformBlockID = glGetUniformBlockIndex(MainOpenGLShaderProgramID, "Matrices");
glUniformBlockBinding(MainOpenGLShaderProgramID, MatricesUniformBlockID, 1);
glGenBuffers(1, &MatricesUniformBufferID);
glBindBuffer(GL_UNIFORM_BUFFER, MatricesUniformBufferID);
glBindBufferBase(GL_UNIFORM_BUFFER, 1, MatricesUniformBufferID);
GLsizeiptr TotalBufferSize = sizeof(glm::mat4) + sizeof(glm::mat4);
TotalBufferSize += sizeof(glm::mat3);

glBufferData(GL_UNIFORM_BUFFER, TotalBufferSize, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, NULL);

LightsUniformBlockID = glGetUniformBlockIndex(MainOpenGLShaderProgramID, "Lights");
glUniformBlockBinding(MainOpenGLShaderProgramID, LightsUniformBlockID, 2);
glGenBuffers(1, &LightsUniformBufferID);
glBindBuffer(GL_UNIFORM_BUFFER, LightsUniformBufferID);
glBindBufferBase(GL_UNIFORM_BUFFER, 2, LightsUniformBufferID);

GLfloat LightDirection[3] = { -4.0f, -3.0f, -3.0f };

glBufferData(GL_UNIFORM_BUFFER, sizeof(LightDirection), &LightDirection, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, NULL);

MaterialsUniformBlockID = glGetUniformBlockIndex(MainOpenGLShaderProgramID, "Materials");
glUniformBlockBinding(MainOpenGLShaderProgramID, MaterialsUniformBlockID, 3);
glGenBuffers(1, &MaterialsUniformBufferID);
glBindBuffer(GL_UNIFORM_BUFFER, MaterialsUniformBufferID);
glBindBufferBase(GL_UNIFORM_BUFFER, 3, MaterialsUniformBufferID);

GLfloat Material[18];

//Diffuse
Material[0] = 0.5f;
Material[1] = 0.0f;
Material[2] = 0.0f;
Material[3] = 1.0f;

//Ambient
Material[4] = 0.2f;
Material[5] = 0.2f;
Material[6] = 0.2f;
Material[7] = 1.0f;

//Specular
Material[8] = 1.0f;
Material[9] = 1.0f;
Material[10] = 1.0f;
Material[11] = 1.0f;

//Emissive
Material[12] = 0.0f;
Material[13] = 0.0f;
Material[14] = 0.0f;
Material[15] = 1.0f;

//Shininess
Material[16] = 5.0f;

//Texture Count
Material[17] = 0.0f;

glBufferData(GL_UNIFORM_BUFFER, sizeof(Material), &Material, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, NULL);

}

最佳答案

你可以尝试一下:

#if defined(Q_OS_WIN32)
#include <GL/glew.h>
#include <GL/wglew.h>
#elif defined(Q_OS_MAC)
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#else
#include <GL/gl.h>
#include <GL/glext.h>
#endif

这就是我们在我现在从事的项目中所做的事情。我不是那个设置它的人,但我认为值得一试。如果您有兴趣查看原始代码,请访问 Github .

关于c++ - 在 Linux 上使用 Qt 5.4 的某些 OpenGL 函数...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28015709/

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