Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Loading GLSL shaders


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Ezbez   Crossbones+   -  Reputation: 1164

Like
0Likes
Like

Posted 11 May 2006 - 10:29 PM

I'm currently trying to load and compile a simple GLSL shader in C++. My code suffers from the copy-and-paste syndrom, but I'm really just trying to learn shaders, not how to load them, so I don't mind too much. Well, here's the code:
	//Load shaders
	GLenum my_program;
	GLcharARB * my_fragment_shader_source;
	GLcharARB * my_vertex_shader_source;

	// Get Vertex And Fragment Shader Sources
	FILE *fp;
	GLubyte *buf;
	int length;
	bool ret = true;

	if (!(fp = fopen("test.vert","rb")))
		printf("Error opening shader.");

	fseek(fp, 0, SEEK_END);
	length = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	my_vertex_shader_source = new GLcharARB[length+1];
	fread( my_vertex_shader_source, 1, length, fp);< -- First error

	if (!(fp = fopen("test.frag","rb")))
		printf("Error opening shader.");

	fseek(fp, 0, SEEK_END);
	length = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	my_fragment_shader_source = new GLcharARB[length+1];
	fread( my_fragment_shader_source, 1, length, fp);< -- Second error 
And Here's the error messages: error C2664: 'void (GLhandleARB,GLsizei,const GLcharARB **,const GLint *)' : cannot convert parameter 3 from 'GLcharARB **' to 'const GLcharARB **' error C2664: 'void (GLhandleARB,GLsizei,const GLcharARB **,const GLint *)' : cannot convert parameter 3 from 'GLcharARB **' to 'const GLcharARB **' The lines that the errors take place on are marked above. Does anyone know how to fix this? I didn't think that converting from a non const to a const variable would cause an error, so I'd geuss that it is something else.

Sponsor:

#2 deavik   Members   -  Reputation: 570

Like
0Likes
Like

Posted 11 May 2006 - 11:35 PM

Quote:
Original post by Ezbez
I'm currently trying to load and compile a simple GLSL shader in C++. My code suffers from the copy-and-paste syndrom, but I'm really just trying to learn shaders, not how to load them, so I don't mind too much.

Well, here's the code:
*** Source Snippet Removed ***

And Here's the error messages:

error C2664: 'void (GLhandleARB,GLsizei,const GLcharARB **,const GLint *)' : cannot convert parameter 3 from 'GLcharARB **' to 'const GLcharARB **'

error C2664: 'void (GLhandleARB,GLsizei,const GLcharARB **,const GLint *)' : cannot convert parameter 3 from 'GLcharARB **' to 'const GLcharARB **'


The lines that the errors take place on are marked above. Does anyone know how to fix this? I didn't think that converting from a non const to a const variable would cause an error, so I'd geuss that it is something else.

Are you sure that the compile errors are from the lines you marked? THey look like they are from glShaderSource (or whatever the corresponding ARB extension function is called).

To solve, you can just use const_cast, or with C-style casting (const GLcharARB**) pointer_to_string.

#3 Ezbez   Crossbones+   -  Reputation: 1164

Like
0Likes
Like

Posted 12 May 2006 - 10:25 AM

Oops, yeah I did give the wrong eror. They are on glShaderSourceARB().

Here's the bit of code that I left out:
	// Create Shader And Program Objects
my_program = glCreateProgramObjectARB();
vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

// Load Shader Sources
// Load Shader Sources
glShaderSourceARB(vertexShader, 1, const_cast<GLcharARB**>(&my_vertex_shader_source), NULL);//First error
delete my_vertex_shader_source;
glShaderSourceARB(fragmentShader, 1, const_cast<GLcharARB**>(&my_fragment_shader_source), NULL);//SecondError
delete my_vertex_shader_source;

with the added const_cast. However, I get the exact same errors as before pointing to the same lines.

Any other ideas?



#4 deavik   Members   -  Reputation: 570

Like
0Likes
Like

Posted 12 May 2006 - 03:47 PM

Quote:
Original post by Ezbez
Any other ideas?

Sure! [grin]

Try const_cast<const GLcharARB**>(&my_fragment_shader_source)

#5 Ezbez   Crossbones+   -  Reputation: 1164

Like
0Likes
Like

Posted 12 May 2006 - 10:09 PM

*wacks self on the head*

Next time I will take the time to fully read the tutorial and make sure that I'm not using the code to get rid of const-ness! Thanks a bunch, it compiles now!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS