PDA

View Full Version : texture and blending



06-01-2005, 01:36 PM
I work on Windows XP and use glut. I don't understand behaviour of my program. Below I list most important:

I defined two function :

void setTexture(GLuint textureName, GLubyte *data)
{
glBindTexture(GL_TEXTURE_2D, textureName);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE );
glTexImage2D(GL_TEXTURE_2D,0,4,N,N,0,GL_RGBA,GL_UN SIGNED_BYTE,data);
}

( N is defined bofore: const int N = 128)
and the second one :

void drawTexture(GLuint textureName, GLint position, GLfloat colour)
{
glBindTexture(GL_TEXTURE_2D,textureName);
glEnable(GL_TEXTURE_2D);


glBegin(GL_QUADS);

glColor3f(colour,0.0,0.0);

glTexCoord2f(0,0);
glVertex3i(0,0,position);

glTexCoord2f(1,0);
glVertex3i(N,0,position);

glTexCoord2f(1,1);
glVertex3i(N,N,position);

glTexCoord2f(0,1);
glVertex3i(0,N,position);

glDisable(GL_TEXTURE_2D);
}

my init() is :
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_FLAT);
glViewport( 0, 0, N,N );
glLoadIdentity();
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, N, 0, N, -256, 256 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

my display function is :
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);

GLuint textureNames[2];
glGenTextures(2,textureNames);

GLubyte *shoe; //triangle is texture date which drawn a shoe for example
GLubyte *flower; ////triangle is texture date which drawn a flower for example

setTexture(textureNames[0],shoe);
setTexture(textureNames[1],flower);

//below is code I have problem:

drawTexture(textureNames[3],1,0.0f);
drawTexture(textureNames[3],2,1.0f);

/* if write it the output will be the same:
drawTexture(textureNames[3],1,1.0f);
drawTexture(textureNames[3],2,0.0f);
*/

glDisable(GL_BLEND);
glEnd();
glFlush();
}

I see always shoe - i don't understant why.
the pointer shoe and flower is ok, if i comment
//drawTexture(textureNames[3],0,0.0f);
the output will be flower.

I really don't understand what's wrong is ? Propobly is stupid mistake. Thanks for any help, and any comments.

06-01-2005, 01:41 PM
sorry for mestake:
there is :
GLubyte *shoe; //triangle is texture date which drawn a shoe for example
GLubyte *flower; ////triangle is texture date which drawn a flower for example

It should be :
GLubyte *shoe; //shoe is texture date which drawn a shoe for example
GLubyte *flower; //flower is texture date which drawn a flower for example

I write one thing more. If i put
drawTexture(textureNames[0],1,0.0f);
drawTexture(textureNames[1],-2,1.0f);

I see black screen :(

plasmonster
06-01-2005, 06:07 PM
For one thing, I don't see a matching glEnd() for your glBegin(GL_QUADS). It looks like it was somehow able to sneak down into another function. Better keep an eye on that one.

When in doubt, it's always a good idea to pepper your code with glGetError() calls; they'll help you catch errors like this early and often.

Maybe I missed something else.

06-01-2005, 10:14 PM
Thanks for help. Yes missing glEnd(); - that was a stupid mistake. I was toiling over that a few hour.