Reputation: 2293
I'd like to create a simple tool to test my shaders. It should try to compile them, and output any messages from the driver. However, I'm having trouble: it segfaults. This is the code:
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/gl.h>
/* Test shader */
static const GLchar * vertexSource =
"#version 150 core\n"
"in vec2 position;"
"in vec3 color;"
"out vec3 Color;"
"void main() {"
" Color = color;"
" gl_Position = vec4(position, 0.0, 1.0);"
"}";
int main(void)
{
GLuint vertexShader;
glewExperimental = GL_TRUE;
glewInit();
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexSource, NULL);
glCompileShader(vertexShader);
glDeleteShader(vertexShader);
return EXIT_SUCCESS;
}
No other messages other than Segmentation fault
are emitted. Can anyone explain what is happening?
P.S.: FWIW, I'm using the R600g Mesa (10.0) driver on a Radeon HD 3200, GCC version 4.8.2.
Upvotes: 4
Views: 543
Reputation: 52083
Create a GL context and make it current before attempting to call glewInit()
or any other GL-related functions.
You can use FreeGLUT to create a window and associated GL context:
#include <GL/glew.h>
#include <GL/freeglut.h>
int main(int argc, char **argv)
{
glutInit( &argc, argv );
glutInitWindowSize( 600, 600 );
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
glutInitContextVersion( 3, 2 );
glutInitContextProfile( GLUT_CORE_PROFILE );
glutCreateWindow( "GLUT" );
glewExperimental = GL_TRUE;
glewInit();
// attempt shader compile here...
glutMainLoop();
return 0;
}
Upvotes: 5