GLSL Error: failed to preprocess the source. How can I troubleshoot this?

Posted by Brent Parker on Stack Overflow See other posts from Stack Overflow or by Brent Parker
Published on 2010-03-31T18:17:45Z Indexed on 2010/03/31 18:23 UTC
Read the original article Hit count: 343

Filed under:
|
|

I'm trying to learn to play with OpenGL GLSL shaders. I've written a very simple program to simply create a shader and compile it. However, whenever I get to the compile step, I get the error:

Error: Preprocessor error Error: failed to preprocess the source.

Here's my very simple code:

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>
#include <time.h>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

const int screenWidth = 640;
const int screenHeight = 480;

const GLchar* gravity_shader[] = {
    "#version 140"
    "uniform float t;"
    "uniform mat4 MVP;"
    "in vec4 pos;"
    "in vec4 vel;"
    "const vec4 g = vec4(0.0, 0.0, -9.80, 0.0);"

    "void main() {"
    "   vec4 position = pos;"
    "   position += t*vel + t*t*g;"

    "   gl_Position = MVP * position;"
    "}"
};

double pointX = (double)screenWidth/2.0;
double pointY = (double)screenWidth/2.0;

void initShader() {
    GLuint shader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(shader, 1, gravity_shader, NULL);
    glCompileShader(shader);
    GLint compiled = true;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
    if(!compiled) {
        GLint length;
        GLchar* log;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
        log = (GLchar*)malloc(length);
        glGetShaderInfoLog(shader, length, &length, log);
        std::cout << log <<std::endl;
        free(log);
    }

    exit(0);
}

bool myInit() {
    initShader();
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glColor3f(0.0f, 0.0f, 0.0f);
    glPointSize(1.0);
    glLineWidth(1.0f);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, (GLdouble) screenWidth, 0.0, (GLdouble) screenHeight);
    glEnable(GL_DEPTH_TEST);

    return true;
}

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(screenWidth, screenHeight);
    glutInitWindowPosition(100, 150);
    glutCreateWindow("Mouse Interaction Display");

    myInit();
    glutMainLoop();

    return 0;
}

Where am I going wrong? If it helps, I am trying to do this on a Acer Aspire One with an atom processor and integrated Intel video running the latest Ubuntu. It's not very powerful, but then again, this is a very simple shader. Thanks a lot for taking a look!

© Stack Overflow or respective owner

Related posts about c++

Related posts about opengl