[QUOTE=Silence;1285363]This does not mean that the code is good This can even mean that there’s a bug in the code. This can also mean that the machine on which it is running does not support some functionalities/extensions (which, from your glext, is not the case), or that your program is not linked with the correct GL library (ie, an old one). Or it might be due to the fact that you use them in a different context than the one they were set.
Let us know how you create your context, how you initialize glew and so on.
Try also to print the value of the function pointers. Maybe one of them is NULL. If so, try to get its address by yourself (ie by using glXGetProcAddress under Unix).[/QUOTE]
Thank you very much for the suggestions, at least it gave me something to google! Apologies for not sending on all the code, I am still familiarising myself with the code base and the GL part is only a small part of the whole program. Here is what I have found so far:
bool initLibraries(const char *title, const int w, const int h)
{
if (!glfwInit()) {
fprintf(stderr, "Error: GLFW could not be initialised. Exiting.
");
return false;
}
g_window = glfwCreateWindow(w, h, title, NULL, NULL);
if (!g_window) {
printf("Error: A window could not be opened. Exiting.
");
glfwTerminate();
return false;
}
g_windowWidth = w;
g_windowHeight = h;
glfwMakeContextCurrent(g_window);
glfwSetCursorEnterCallback(g_window, cursorEnterCallback);
GLenum result = glewInit();
if (result != GLEW_OK) {
printf("Error: GLEW could not be initialised.
");
printf("%s. Exiting.
", glewGetErrorString(result));
glfwTerminate();
return false;
}
return true;
}
/*
* Initialise renderer
*/
if (!initLibraries("VOLA Renderer", (dualView) ? 1600 : 800, 800)) {
svo_del(g_svo);
return EXIT_FAILURE;
}
const char *fshader = "shaders/fragmentShader.glsl";
const char *vshader = "shaders/vshader.glsl";
char *shaderMessage = NULL;
GLuint fshdr = loadShader(GL_FRAGMENT_SHADER, fshader, &shaderMessage);
if (shaderMessage) {
fprintf(stderr, "%s
", shaderMessage);
shaderMessage = NULL;
}
GLuint vshdr = loadShader(GL_VERTEX_SHADER, vshader, &shaderMessage);
if (shaderMessage) {
fprintf(stderr, "%s
", shaderMessage);
shaderMessage = NULL;
}
/* Link the shaders. */
GLuint shader = glCreateProgram();
glAttachShader(shader, fshdr);
glAttachShader(shader, vshdr);
glLinkProgram(shader);
GLint stat;
glGetProgramiv(shader, GL_LINK_STATUS, &stat);
if (!stat) {
GLint len;
glGetProgramiv(shader, GL_INFO_LOG_LENGTH, &len);
GLchar err[len];
glGetProgramInfoLog(shader, len, &len, err);
printf("%s
", err);
glfwTerminate();
return EXIT_FAILURE;
}
glUseProgram(shader);
struct ShaderLocations locs = {
.colours = glGetAttribLocation(shader, "colour"),
.normals = glGetAttribLocation(shader, "normal"),
.occlusions = glGetAttribLocation(shader, "occlusion"),
.positions = glGetAttribLocation(shader, "position"),
.useLighting = glGetUniformLocation(shader, "useLighting"),
.useAmbientOcclusion = glGetUniformLocation(shader, "useAmbientOcclusion"),
.useSingleColour = glGetUniformLocation(shader, "useSingleColour"),
.passThrough = glGetUniformLocation(shader, "passThrough"),
.singleColour = glGetUniformLocation(shader, "singleColour"),
.cameraInverseT = glGetUniformLocation(shader, "cameraInverseT"),
.cameraInverseRx = glGetUniformLocation(shader, "cameraInverseRx"),
.cameraInverseRy = glGetUniformLocation(shader, "cameraInverseRy"),
.cameraInverseRz = glGetUniformLocation(shader, "cameraInverseRz"),
.perspectiveProjection = glGetUniformLocation(shader, "perspectiveProjection"),
.modelMatrix = glGetUniformLocation(shader, "modelMatrix"),
.lightPosition = glGetUniformLocation(shader, "lightPosition"),
.lightIntensity = glGetUniformLocation(shader, "lightIntensity")
};
g_camera = cameraNew(0, 0, 0, 45.0f, -135.0f, 0, 25, 50, true, 1, 0);
/* Load the perspective projection matrix into the shaders. */
float perspectiveMat[16];
pers(perspectiveMat, 1.0f, 1000.0f, -1.0f, 1.0f, 1.0f, -1.0f);
glUniformMatrix4fv(locs.perspectiveProjection, 1, GL_TRUE, perspectiveMat);
/* ************************************************************************** */
/* Light position should be a function of the scene size and oblique
* to the voxel faces for good results */
const float lightX = g_svo->len / 3.1f;
const float lightY = 2000;
const float lightZ = g_svo->len / 2.1f;
const float lightIntensity = 2.5f;
glUniform4f(locs.lightPosition, lightX, lightY, lightZ, 1.0f);
glUniform1f(locs.lightIntensity, lightIntensity);
/* ************************************************************************** */
/* Main loop ******************************************************************/
glEnable(GL_SCISSOR_TEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPointSize(2.0f);
/* Used to track the time elapsed between frames. */
float prevt, currt;
/* Used to track cursor position. */
double cx, cy, cxprev, cyprev;
glfwGetCursorPos(g_window, &cxprev, &cyprev);
glUniform1i(locs.passThrough, 0);
And here is some of the code for drawing the mesh. It initially is drawing the axes, which works fine so it is capable of drawing a mesh, just not the main mesh!
/* Draw the X, Y and Z axes. */
if (g_drawAxes) {
glUniform1i(locs.useLighting, 0);
glUniform1i(locs.useAmbientOcclusion, 0);
glUniform1i(locs.useSingleColour, 0);
glBindVertexArray(axesMesh.VAO);
printf("axesmesh VAO %u
", axesMesh.VAO);
glDrawArrays(axesMesh.mode, 0, 6);
}
glUniform1i(locs.useLighting, g_lightingEnabled);
if (g_useLevelOfDetail && g_showLevelOfDetail) {
float LODColour[] = {0.0f, 1.0f, 0.0f, 1.0f};
glUniform1i(locs.useSingleColour, 1);
glUniform4fv(locs.singleColour, 1, LODColour);
glBindVertexArray(LODGLMeshes[g_LOD].VAO);
glDrawArrays(GL_TRIANGLES, 0, LODGLMeshes[g_LOD].mesh.positions.length / 3);
} else {
/* Draw the volume contents. */
glUniform1i(locs.useSingleColour, !g_usingColour);
glUniform1i(locs.useAmbientOcclusion, 1);
float singleColour[4] = {0.1f, 1.0f, 0.2f, 1.0f};
glUniform4fv(locs.singleColour, 1, singleColour);
glBindVertexArray(voxelMesh.VAO);
printf("voxsize:%d
", getGLMeshSize(voxelMesh));
if (g_drawVoxelsWireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
printf("drawvox num voxel %d
", num_voxel_vertices);
printf("drawvox mode %d
", voxelMesh.mode);
printf("drawvox VAO %u
", voxelMesh.VAO);
printf("vox size%u
", voxelMesh.mesh.positions.elementSize);
printf("vox length %u
", voxelMesh.mesh.positions.length);
glDrawArrays(voxelMesh.mode, 0, num_voxel_vertices);
printf("drawvox finished
");
Regarding the libraries, I checked them using ldd and GLEW and GLFW are pointing to the libraries I installed. I compared them with the libraries linked on the virtual machine and spotted some differences:
linux-vdso.so.1 => (0x00007ffe537f6000)
libvola.so => /home/jonathan/data/Jonathan/programs/MvOLA/VOLA/build/libvola.so (0x00007f5f4a326000)
libGL.so.1 => /usr/lib/nvidia-367/libGL.so.1 (0x00007f5f4a065000)
libGLEW.so.1.13 => /usr/lib/x86_64-linux-gnu/libGLEW.so.1.13 (0x00007f5f49de1000)
libglfw.so.3 => /usr/lib/x86_64-linux-gnu/libglfw.so.3 (0x00007f5f49bcb000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5f498c2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5f494f8000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5f48f60000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5f48d5b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5f48638000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f5f482fe000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5f480e1000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f5f47ed5000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f5f47cd2000)
libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007f5f47ac2000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f5f478bb000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f5f476b1000)
/lib64/ld-linux-x86-64.so.2 (0x000055e2dc0ce000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f5f4749e000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f5f4727c000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f5f47071000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f5f46e6b000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f5f46c67000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f5f46a60000)
These libraries were not linked on the virtual machine:
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5f49176000)
libGLX.so.0 => /usr/lib/nvidia-367/libGLX.so.0 (0x00007f5f48b2a000)
libGLdispatch.so.0 => /usr/lib/nvidia-367/libGLdispatch.so.0 (0x00007f5f48841000)
And these libraries were linked on the virtual machine but not on my main machine:
libexpat
libXdamage
libdrm
finally I tried calling glXGetProcAddress on the glDrawArrays function but it said it is not in the scope. Is it in the GLEW and GLFW libraries or do I need to import another library.
Thanks again for all the help!