Jump to content
  • Advertisement
Sign in to follow this  
alberich2k5

OpenGL tuxtures with glsl

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

Hi!! I'm just playing with opengl, i'm really newbie on this. I'm able now to use shaders with my code, but i cannot use textures with glsl. Anyone can point me how to texturize with glsl? I need to upload them to glsl, like with uniforms and vector? I'm lost.. thanks!!

Share this post


Link to post
Share on other sites
Advertisement
Thanks!!!

But it's still not working :( i think i'm missing something.

Is there soma basic tutorial to load a texture and use glsl to render it??

Or can anyone pointme to the steps i need to follow?

thanks!!!

Share this post


Link to post
Share on other sites
THanks!!!

This tutorial, just talks about glsl. I'm looking for something more basic, how to upload texture to glsl..generate textures. I think i'm missing something on opengl part..

Share this post


Link to post
Share on other sites
uniform sampler2D yourtexture;

void main()
{
gl_FragData = texture2D(yourtexture);
}


your c++ code:

int location = glGetUniformLocation(program_handle, "yourtexture");
glUniform1i(location, 0);

Share this post


Link to post
Share on other sites
This is what i'm doing:

on initGL:

LoadGLTextures()) initGlew();
shader.loadShaders("shaders/shader.ps","shaders/shader.vs"))
glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
---------------------------------------------------------------

This is what LoadGLTextures() does:
img.loadBMP("textures/lion.bmp");
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3,img.width, img.height, 0, GL_RGB,GL_UNSIGNED_BYTE, img.data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
---------------------------------------------------------------

On drawing scene:

shader.enable();
shader.addTexture("base",0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glVertex3f(-1, 0, 1);
glVertex3f( 1, 0, 1);
glVertex3f( 1, 0, -1);
glVertex3f(-1, 0, -1);
glEnd();
shader.disable();
---------------------------------------------------------------
MY shaders:

[pixel shader]
uniform sampler2D base;
void main (void)
{
vec4 color = texture2D( base, gl_TexCoord[0].st);
gl_FragColor = color;
}
[vertex shader]
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
---------------------------------------------------------------

This just draws an empty quad, with no texture.
But if i use glTexCoord2f when drawing the quad, it works:

glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);



What i am doing wrong?
thanks!!!

Share this post


Link to post
Share on other sites
Quote:
Original post by alberich2k5
What i am doing wrong?
thanks!!!


You didn't send texture coordinates, you must send them to GL if you want to use textures.

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!