This topic is 4270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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;

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

if (!(fp = fopen("test.vert","rb")))

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

if (!(fp = fopen("test.frag","rb")))

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


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.

##### Share on other sites
Quote:
 Original post by EzbezI'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.

##### Share on other sites
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?

##### Share on other sites
Quote:
 Original post by EzbezAny other ideas?

Sure! [grin]