Skip to main content
gamedev.net
🔒 Locked

GLSL problem...

Started by Tree Penguin Nov 22, 2004 at 5:19 PM 3 replies 950+ views
Original Post
Tree Penguin
Tree Penguin
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.
PinguinDude
PinguinDude
Then it's your code.
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
Tree Penguin
Tree Penguin
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 Objectsmy_program = glCreateProgramObjectARB();my_vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);	// Load Shader SourcesglShaderSourceARB(my_vertex_shader, 1, getGLcharARBxx(&my_vertex_shader_source), NULL);	// Compile The ShadersglCompileShaderARB(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 ObjectglAttachObjectARB(my_program, my_vertex_shader);	// Link The Program ObjectglLinkProgramARB(my_program);	// Use The Program Object Instead Of Fixed Function OpenGLglUseProgramObjectARB(my_program);


[Edited by - Tree Penguin on November 22, 2004 6:44:03 PM]
Enigma
Enigma
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
Tree Penguin
Tree Penguin
I made a pretty stupid mistake, i passed the shader's filename instead of the shader contents to glShaderSourceARB.

Thanks for your help anyway.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.