problems getting started with shaders *solved*

Started by
6 comments, last by Dragon_Strike 17 years, 7 months ago
ok ive tried the shader class form the book "more opengl"... for some reason my program crashes when i try to send a unidorm... so i wne t to the lighthouse tutorial and followed it... but now when i use the shader... nothin happens... here is just a simple example where i try t make the shader do SOMETHING... the program compiles and runs jsut fine but as i said the shader doesnt do anything...


/// CLASS VARIABLE
GLuint p,f,v;

////////INIT FUNCTION
		char *vs,*fs;
	
		v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
		f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);	
	
		vs = ReadFile("shader.vert");
		fs = ReadFile("shader.frag");
	
		const char * vv = vs;
		const char * ff = fs;
	
		glShaderSourceARB(v, 1, &vv,NULL);
		glShaderSourceARB(f, 1, &ff,NULL);
	
		free(vs);free(fs);
	
		glCompileShaderARB(v);
		glCompileShaderARB(f);
	
		p = glCreateProgramObjectARB();
		
		glAttachObjectARB(p,v);
		glAttachObjectARB(p,f);
	
		glLinkProgramARB(p);
		glUseProgramObjectARB(p);

//// TEXTFILE READ

char* CCHUNKTREE::ReadFile(char* filename)
{
	ifstream temp(filename);
	int count = 0;
	char *buf;
	  
	temp.seekg(0, ios::end);
	count = temp.tellg();
	  
	buf = new char[count + 1];
	memset(buf,0,count);
	temp.seekg(0, ios::beg);
	temp.read(buf, count);
	buf[count] = 0;
	temp.close();
	  
	return buf;
}

/// SHADER.VERT

#version 110

uniform float Morph;

void main()
{
	glTexCoord[0] = gl_MultiTexCoord0;
	gl_Position = (gl_Vertex+100)*gl_ModelViewMatrix;
}

// SHADER.FRAG

#version 110

void main()
{

	gl_FragColor = gl_Color+;	
}



[Edited by - Dragon_Strike on September 14, 2006 5:04:22 PM]
Advertisement
Why gl_vertex+100?

And by "the shader doesn't do anything", do you mean the object does not appear?
Without order nothing can exist - without chaos nothing can evolve.
Because the uniform you have from what I see in your code isn't bound on the CPU side, so my bet is if you comment it out you will be able to run the shader, you need to get a uniform location for that float Morph variable so the shader has a location to get data from...
Quote:Original post by MARS_999
Because the uniform you have from what I see in your code isn't bound on the CPU side, so my bet is if you comment it out you will be able to run the shader, you need to get a uniform location for that float Morph variable so the shader has a location to get data from...


i dont rly understand what that means... mind explaining a bit simpler.. im jsut a beginner
Quote:Original post by CyberSlag5k
Why gl_vertex+100?

And by "the shader doesn't do anything", do you mean the object does not appear?


well i just took something that would change the geometry soo that i could see if the shader works... and it should say gl_vertex.y+100.. its just an example.. nothing i write in the shader changes anything form when i dont use it..
Are you sure the shaders/program are/is successfully being compiled/linked? Are you checking the info logs? Are you sure the program is bound when you're rendering? OpenGL expects gl_Position to be the homogeneous vertex coordinates, so if you're trying to conform to what OpenGL expects the vertex should be transformed by the modelview and projection matrices (gl_ModelViewProjectionMatrix). You're also multiplying in the wrong order.
Quote:Original post by Dragon_Strike
and it should say gl_vertex.y+100.. its just an example..
You should copy/paste your exact code when asking for help, otherwise we'll worry about fixing typos that aren't actually there.
Ok, let's fix the vertex shader so we can rule that out. Replace the gl_Position line you presently have with:

gl_Position = ftransform();

That is more or less equivilent to what Kalidor said (gl_Position = gl_ModelViewProjectionmatrix * gl_Vertex), which is the correct way to transform your models into world space.

However! I highly doubt that is your present problem. As there is no difference between what you've got posted with the gl_Vertex+100 thing and the fixed functionality, I'm guessing you're not actually applying the shader. Check and make sure the shaders are compiling correctly (again ala Kalidor), and if they are, post the (exact) application code, including where you're doing your drawing.
Without order nothing can exist - without chaos nothing can evolve.
EDIT:

thx for the tip with the logs.. helps alot...

*SOLVED*

[Edited by - Dragon_Strike on September 14, 2006 4:12:54 PM]

This topic is closed to new replies.

Advertisement