PDA

View Full Version : Couple GLSL questions.



Lehm
05-20-2005, 12:15 PM
I was trying regular blending to composite 3 or 4 textures along with the polygon color. It's ended up rather tricky and someone mentioned I should look into doing it with a pixel shader instead. I was following this tutorial. http://www.lighthouse3d.com/opengl/glsl/index.php?oglexample1

I can get it to compile with no errors but nothing shows up. So I had a few questions to make sure I was doing things right. First of all is that all the code necessary for a program to use a shader. Second can you have a fragment shader without a vertex shader? Third what do the lines...

const char * vv = vs;
const char * ff = fs;

do? Well not what they do, I know that, but how important are they? Because I'm using c# and not c++ and it doesn't like the fact that those lines are stuck in the middle. Oh and I am right in thinking that this will paint every fragment red right?

void main(void)
{
gl_FragColor = vec4 (1.0,0.0,0.0, 1.0);
}

I know these are newbie questions, but you got to learn somehow.

Trahern
05-20-2005, 04:06 PM
Originally posted by Lehm:
I was trying regular blending to composite 3 or 4 textures along with the polygon color. It's ended up rather tricky and someone mentioned I should look into doing it with a pixel shader instead. I was following this tutorial. http://www.lighthouse3d.com/opengl/glsl/index.php?oglexample1

I can get it to compile with no errors but nothing shows up. So I had a few questions to make sure I was doing things right. First of all is that all the code necessary for a program to use a shader. Second can you have a fragment shader without a vertex shader? Third what do the lines...

const char * vv = vs;
const char * ff = fs;

do? Well not what they do, I know that, but how important are they? Because I'm using c# and not c++ and it doesn't like the fact that those lines are stuck in the middle. Oh and I am right in thinking that this will paint every fragment red right?

void main(void)
{
gl_FragColor = vec4 (1.0,0.0,0.0, 1.0);
}

I know these are newbie questions, but you got to learn somehow.1. yes, if you want to use GLSL you have to do almost all the things included in the code

2. yes you can use only vertex or fragment shader. However I have heard that there are some problems with it on ATIs ( I'm not sure if the problems are still there or not .. )

3. I think they are there only to cast char* to const char* ..nothing important

4. Yes it should paint all fragments red. ( but you have to select right position of fragments in vertex shader ( ie. gl_Position=ftransform(); }

Lehm
05-20-2005, 10:25 PM
Originally posted by Trahern:

4. Yes it should paint all fragments red. ( but you have to select right position of fragments in vertex shader ( ie. gl_Position=ftransform(); }[/QB]So what your saying is that I have to use a vertex shader to specify gl_FragColor? If so it's possible to write a VS that just uses the built in transforms right?

Trahern
05-21-2005, 01:33 AM
Originally posted by Lehm:

Originally posted by Trahern:

4. Yes it should paint all fragments red. ( but you have to select right position of fragments in vertex shader ( ie. gl_Position=ftransform(); }So what your saying is that I have to use a vertex shader to specify gl_FragColor? If so it's possible to write a VS that just uses the built in transforms right?[/QB]no you dont have to use a vertex shader to specify gl_FragColor. You just have to specify position of a vertex in vertex shader ( and of course only if you are using a VS .. if not then the standard openGL vertex shader should specify the position for you ( but to be honest I have never tried this ..I always use both vertex and fragment shader ))

Lehm
05-21-2005, 11:04 AM
Well okay. I decided to add a vertex shader that simply does...

void main()
{
gl_Position = ftransform();
}

But I still get nothing. I'e followed the tutorial as closely as I could. The only difference being those const lines. I get no errors and everything seems to be loading properly. Any ideas on where to start debugging? I don't know enough to know why it simply wouldn't show up.

zed
05-21-2005, 11:45 AM
download someone elses code that does the same thing + see why that works and why youres doesnt, step through with a debugger and see where they differ

Lehm
05-28-2005, 03:31 PM
Finally figured it out. It was being enabled, but if you changed screen resolutions it was disabled. So the solution was just to reload the shaders everytime the resolution changed.