[英]OpenGL - shader test
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. 除了Segmentation fault
不会发出其他消息。 Can anyone explain what is happening? 任何人都可以解释发生了什么?
PS: FWIW, I'm using the R600g Mesa (10.0) driver on a Radeon HD 3200, GCC version 4.8.2. PS:FWIW,我在Radeon HD 3200,GCC版本4.8.2上使用R600g Mesa(10.0)驱动程序。
Create a GL context and make it current before attempting to call glewInit()
or any other GL-related functions. 在尝试调用glewInit()
或任何其他GL相关函数之前,创建GL上下文并使其成为当前上下文。
You can use FreeGLUT to create a window and associated GL context: 您可以使用FreeGLUT创建窗口和关联的GL上下文:
#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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.