Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

OpenGL problems getting started with shaders *solved*

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!