PDA

View Full Version : OpenGL 3.0 and texture



Pswin
09-15-2009, 03:53 AM
hi

working with textures in OpenGL3.x is like as other versions of OpenGL (for example 2.1,2.0)???

i know this is like as silly question, but i read a documention in the web (about 1 mounth ago) which writes
working with textures is not like in the other version and u dosnet need to use glEnable(GL_TEXTURE_ ...

Dark Photon
09-15-2009, 05:37 AM
Creating and populating the textures is largely the same.

It's when you go to use the textures things differ, if you are using shaders. You still bind textures to texture units as before, but instead of telling the hardware how to generate the shader (e.g.:


glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
this being one small piece of the "shader" logic), you write the shader yourself, give it to the driver, and then bind it to make it active. Your shader is coded with the logic to sample specific texture units and combine them in some way you find useful.

V-man
09-15-2009, 08:18 AM
That is correct, when using shaders, you don't need to enable (glEnable(GL_TEXTURE_2D))
It has been this way since shaders were first introduced, which was even before GL 2.0

I recommend reading the Wiki

http://www.opengl.org/wiki/GLSL_:_common_mistakes

Pswin
09-15-2009, 10:59 AM
eemmmmmmmmmmmmmmmm

activing all texture unit in OGL 3.x or 2.x with using of shaders can hit program performance.

for example in my game engine, i want to active all texture units in start up render rather than activing them in every frame or evey bind.

Pswin
09-15-2009, 11:56 AM
this is my shader program for basic texturing, why it dosent work?

vertex :


#version 150
in vec3 in_Position;
in vec2 in_TexCoord;
out vec2 texcoord;
void main(void)
{

gl_Position = vec4(in_Position, 1.0);
texcoord = in_TexCoord;
}


fragment:


#version 150 core
in vec2 texcoord;
out vec4 out_Color;
uniform sampler2D Tex1;
void main(void)
{
out_Color = texture2D(Tex1,texcoord);
}

Dark Photon
09-15-2009, 05:45 PM
this is my shader program for basic texturing, why it dosent work?
Well, without seeing the whole program, could be anything. But the one thing that looks a little fishy in your shader is that you're using the position vertex attribute directly as your vertex shader output position:


vertex :

...
gl_Position = vec4(in_Position, 1.0);
...

It's not that it "can't" work (if you feed the right clip-space vertex attribute positions in), but typically you'll feed in object-space vertex positions and then see this multiplied by ModelViewProjection in the vertex shader.

Regardless, there may be problem(s) in your C++ code though, particularly if the above is what you meant to do.

Pswin
09-16-2009, 04:14 AM
hi

i found problem, texture is not created successfully, becase i bind texture after setting target params. target prams must be seted after binding texture