Sign in to follow this  
Tree Penguin

GLSL problem...

Recommended Posts

Tree Penguin    262
I am trying to get basic glsl shaders to work but i get a 'Ongeldige Bewerking' (i think the correct translation is 'Invalid Exception') ogl error after calling glUseProgramObjectARB. As a result the quad i draw is white instead of colored (what my shader should do, it's just not executed). I am not feeling like posting all of the code so if anyone could tell me at what places the cause of the error can be i will post that code. Tnanks a lot. Btw, if you need me to describe my problem better please say so. EDIT: i am able to run my shader with the glsl demo viewer from the 3dlabs website so that can't be the problem.

Share this post


Link to post
Share on other sites
Tree Penguin    262
Ah sorry, i checked and the vertex program just isn't compiled in my app, is there something wrong with:
void main()
{
gl_Position = vect4 (1.0,1.0,1.0,1.0);
gl_Color=vec4(0.5,1.0,1.0,1.0);
}



?

Have i forgotten anything?

Hmm i guess it's the compiler (maybe it's not there or something).

EDIT: here's the code:
GLhandleARB my_program;
GLhandleARB my_vertex_shader;

// Create Shader And Program Objects
my_program = glCreateProgramObjectARB();
my_vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
// Load Shader Sources
glShaderSourceARB(my_vertex_shader, 1, getGLcharARBxx(&my_vertex_shader_source), NULL);

// Compile The Shaders
glCompileShaderARB(my_vertex_shader);

int vertCompiled=0;
glGetObjectParameterivARB(my_vertex_shader,GL_OBJECT_COMPILE_STATUS_ARB, &vertCompiled);
if(!vertCompiled)MessageBox(NULL,"Vp compile failed.","ERROR",NULL);

// Attach The Shader Objects To The Program Object
glAttachObjectARB(my_program, my_vertex_shader);

// Link The Program Object
glLinkProgramARB(my_program);

// Use The Program Object Instead Of Fixed Function OpenGL
glUseProgramObjectARB(my_program);


[Edited by - Tree Penguin on November 22, 2004 6:44:03 PM]

Share this post


Link to post
Share on other sites
Enigma    1410
If you're using windows then make sure you've properly loaded the function pointers for GlSlang functions, since they're only accessible as extensions.

Here's my (quickly hacked) shader loading code from a recent project, it outputs debug information to the console if shader compilation fails:
char* readFile(const char* fileName)
{
std::ifstream reader(fileName, std::ios::in | std::ios::binary);
reader.seekg(0, std::ios::end);
unsigned int fileLength = reader.tellg();
reader.seekg(0, std::ios::beg);
char* file = new char[fileLength + 1];
file[fileLength] = '\0';
reader.read(file, fileLength);
return file;
}

GLhandleARB loadShader(const char* shaderSource, GLenum type)
{
GLhandleARB shader = glCreateShaderObjectARB(type);
char* shaderCode = readFile(shaderSource);
int shaderLength = -1;
glShaderSourceARB(shader, 1, &shaderCode, &shaderLength);
delete[] shaderCode;
glCompileShaderARB(shader);
int objectParameter;
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &objectParameter);
if (!objectParameter)
{
std::cout << "shader error\n";
int infoLogLength;
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infoLogLength);
char* infoLog = new char[infoLogLength];
glGetInfoLogARB(shader, infoLogLength, 0, infoLog);
std::cout << infoLog << '\n';
delete[] infoLog;
std::exit(-1);
}
return shader;
}

GLhandleARB buildShaderProgram(std::vector<GLhandleARB> shaders)
{
GLhandleARB program = glCreateProgramObjectARB();
for (unsigned int index = 0; index < shaders.size(); ++index)
{
glAttachObjectARB(program, shaders[index]);
}
glLinkProgramARB(program);
int objectParameter;
glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &objectParameter);
if (!objectParameter)
{
std::cout << "program error\n";
int infoLogLength;
glGetObjectParameterivARB(program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infoLogLength);
char* infoLog = new char[infoLogLength];
glGetInfoLogARB(program, infoLogLength, 0, infoLog);
std::cout << infoLog << '\n';
delete[] infoLog;
std::exit(-1);
}
return program;
}

void initShaders()
{
std::vector<GLhandleARB> shaders;
shaders.push_back(loadShader("vertexProgram.slang", GL_VERTEX_SHADER_ARB));
shaders.push_back(loadShader("fragmentProgram.slang", GL_FRAGMENT_SHADER_ARB));
shader1 = buildShaderProgram(shaders);
shaders.clear();
shaders.push_back(loadShader("vertexProgram.slang", GL_VERTEX_SHADER_ARB));
shader2 = buildShaderProgram(shaders);
shaders.clear();
}


Enigma

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this