Jump to content
  • Advertisement
Sign in to follow this  
dc443

OpenGL primitives and textures in GLSL

This topic is 3711 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

I have an SDL-OpenGL program that I am incorporating GLSL shaders into. Most of the entities are not textured and are just simple polygons (GL_TRIANGLE_FAN, GL_POLYGON, what have you). I intend to use shaders not for lighting at all, but for effects like particle systems, bloom, visual distortions. I've gotten shader code to finally work, but I am a little confused as to how textures are handled. I can't seem to find any shader code that will function identically to the fixed-function pipeline... all I can find are tutorials for lighting and multitexturing and various basic 3D things that I don't need. Can somebody point me in the right direction? thanks.

Share this post


Link to post
Share on other sites
Advertisement
You have to decide on what you want to acheive.
The fixed function pipeline is vast. Whenever you change something in the fixed function, the GL driver generates a shader and uploads it. I'm assuming you want something simple. If you just want to sample a texture and output, then that is easy to do


uniform sampler2D Texture0;

void main()
{
gl_FragColor = texture2D(Texture0, gl_TexCoord[0].xy);
}




but that is just for fragment shader.

Share this post


Link to post
Share on other sites
I want to know how this affects the code in my openGL c++ code. I see a billion examples of what to put in the shader, but never of what the hell goes on in the actual program itself!!! What I want to know is, will I need something like this: and if so, what do i put in the first block:


if (isShading)
{
/// specific code to set up texture for shader -- i cannot find any examples of what to do here....
glUniform1i(texLoc, glTexture); // for the sampler2D uniform or some-such
}
else
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, glTexture);
glBegin(GL_QUADS);
// blah (this is the stuff that I am currently doing, and am used to and fully understand)
glEnd();
glDisable(GL_TEXTURE_2D);
}







What do I do with the Texture0? Do i pass it through a glUniform1i? is Texture0 a built-in uniform? (it can't be, though because then you don't need to declare it..)

I can't believe how hard it is to find information on these basic basic things.

Share this post


Link to post
Share on other sites
Lighthouse3D wasnt really detailed enough. I think I found what I'm looking for here: http://www.typhoonlabs.com/

Share this post


Link to post
Share on other sites
Thanks for the help everyone. V-man, that link is very helpful.

So, i've gotten things working, somehow. I don't have anything like this

location=glGetUniformLocation(shaderProgram, "Texture0");
glUniform1i(location, 0);



to specify the texture, but for some reason it mysteriously just works. I'm not complaining about that just yet.

Since I will be doing some post processing effects, I will copy the backbuffer to a texture, and draw it by enabling my shader and then drawing a full-screen quad with the texture, and the shader will be able to sample all pixels on the texture.

From what I understand this will require a bunch more fillrate because it renders the scene, then renders the quad with the updated scene on top of it, and yet again for every pass that I make (a bloom/blur filter will be two passes). Are there better methods to do this? If I have a distortion effect that does not involve the entire screen, maybe I could just copy a portion of the screen to texture?

Share this post


Link to post
Share on other sites
>>to specify the texture, but for some reason it mysteriously just works. I'm not complaining about that just yet.

I assume if nothings specified then they just use textureunit 0 (ie its the default)
if u wanna access non textureunit0 in shaders this will become as issue

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
>>to specify the texture, but for some reason it mysteriously just works. I'm not complaining about that just yet.

I assume if nothings specified then they just use textureunit 0 (ie its the default)
if u wanna access non textureunit0 in shaders this will become as issue


Well I didnt make any calls to send the texture to a uniform sampler2d.

I won't be multitexturing anyways so I think i'm good as far as that's concerned.

Share this post


Link to post
Share on other sites
Although, if I'm doing bloom, in order to apply the effect, should I multitexture in a shader, or should I draw an additional quad with the bloom texture and blend it?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!