You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, January 18th 2015, 10:05pm

Using certain OpenGL functions on Linux…

Hello,

The following code block below works on Windows (in VC++ 2013) because I have included GL/glew.h but using QT Creator on Linux it undefines the include so the functions in bold below are not available.

What can I do to be able to use the OpenGL functions glGetUniformBlockIndex(),glUniformBlockBinding(), and glBindBufferBase() under Linux like how I use these functions under Windows?

Thank you for your time.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
 
}