Setting back the textures
Hello, right now I am delving into particle generators and have come up to a problem. After binding a pseudo-texture to my particles, all my other objects have the same textures as my particles, how do I get rid of it?
[souce]
...
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texPixels);
...
[/source]
Thanks in advance
Get the specification. Read it.
Specifically, make sure you understand the operation of glBindTexture.
Specifically, make sure you understand the operation of glBindTexture.
glEnable(GL_TEXTURE_2D);
glBindTexture();
draw_particles();
glDisable(GL_TEXTURE_2D);
draw_everything_else();
glBindTexture();
draw_particles();
glDisable(GL_TEXTURE_2D);
draw_everything_else();
Thanks for the help, but that isn''t what I was looking for. Once I apply a texture, the texture stays on all the other objects that I draw. I wanted a different texture for each object, and my normal way was to initiate
glBindTexture(GL_TEXTURE_2D, texture[x]); before every object that I draw to bind a different texture, noted by x, but the same texture stays on no matter what I do.
glBindTexture(GL_TEXTURE_2D, texture[x]); before every object that I draw to bind a different texture, noted by x, but the same texture stays on no matter what I do.
you are probably calling glBindTexture(GL_TEXTURE_2D, texture[x]) within a glBegin()/glEnd() block. if you are, the texture binding calls inside glBegin()/glEnd() wont work.
Thanks xiros, but I was calling glBindTexture(GL_TEXTURE_2D, texture[x]); outside of the glBegin()/glEnd() block.
Here is the particle's code
[edited by - Xiachunyi on April 20, 2003 10:43:08 PM]
Here is the particle's code
int setCheckTexture(void){ int texWidth = 256; int texHeight = 256; GLubyte *texPixels, *p; int texSize; int i, j; int radius; texSize = texWidth*texHeight*4*sizeof(GLubyte); texPixels = (GLubyte *) malloc(texSize); if (texPixels == NULL) { return false; } p = texPixels; for (i=0; i<texHeight; ++i) { for (j=0; j<texWidth; ++j) { double dist = hypot(float(i - (texHeight / 2)),float(j - (texWidth / 2))); float color = 255-(dist*1.8); if (color < 0) color = 0; p[0] = color; p[1] = color; p[2] = color; p[3] = color; p+=4; } } glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texPixels); free(texPixels); return true;}void particle_generate(double x, double y, double z, double r_color,double b_color, double g_color){ glLoadIdentity(); glTranslatef(x,y,z); for (loop_particle=0; loop_particle<MAX_PARTICLES; loop_particle++) { float x=particle[loop_particle].x; float y=particle[loop_particle].y; float z=particle[loop_particle].z; glColor4f(r_color,b_color,g_color,particle[loop_particle].life); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(1,1); glVertex3f(x+0.2f,y+0.2f,z); glTexCoord2f(0,1); glVertex3f(x-0.2f,y+0.2f,z); glTexCoord2f(1,0); glVertex3f(x+0.2f,y-0.2f,z); glTexCoord2f(0,0); glVertex3f(x-0.2f,y-0.2f,z); glEnd(); particle[loop_particle].x+=particle[loop_particle].xi/250; particle[loop_particle].y+=particle[loop_particle].yi/250; particle[loop_particle].z+=particle[loop_particle].zi/250; particle[loop_particle].xi*=.99; particle[loop_particle].yi*=.99; particle[loop_particle].zi*=.99; particle[loop_particle].life-=particle[loop_particle].fade; if (particle[loop_particle].life<0.05f) { particle[loop_particle].life=1.0f; particle[loop_particle].fade=float(rand()%100)/10000 + 0.005f; particle[loop_particle].x= 0; particle[loop_particle].y= 0; particle[loop_particle].z= 0; V = (float((rand()%9))+1); Angle = float(rand()%360); particle[loop_particle].xi = sin(Angle) * V; particle[loop_particle].yi = cos(Angle) * V; particle[loop_particle].zi = ((rand()%10)-5)/5; } } } [/code] I call setCheckTexture(); first and the generate the points.Here is the function I am calling[code]void gl_drawcube(int tex_count, int pic1, int pic2, int pic3, int pic4, int pic5, int pic6, double x, double y, double z, double placex, double placey, double placez){ glLoadIdentity(); glColor4f(1.0,1.0,1.0,1.0); glTranslatef(placex,placey,placez); glRotatef(xrot_cube,1.0f,0.0f,0.0f); glRotatef(yrot_cube,0.0f,1.0f,0.0f); glRotatef(zrot_cube,0.0f,0.0f,1.0f); glBindTexture(GL_TEXTURE_2D, texture[pic1]); glBegin(GL_QUADS); // Front Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); 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); // Back Face 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); // Top Face glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Bottom Face 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); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face 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); // Left Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); 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); xrot_cube=xrot_cube+x; yrot_cube=yrot_cube+y; zrot_cube=zrot_cube+z; glEnd(); }
[edited by - Xiachunyi on April 20, 2003 10:43:08 PM]
It seems to me that your not telling it where you want the texture...
in your texture loading function notice I added glBindTexture(GL_TEXTURE_2D, texture[x]); this links the texture you making with texture[x] so no when you call glBindTexture before a polygon it know what texture to use. You can have as many different textures as you want just make sure to change the variable... texture[0], texture[1]... etc... hope that helps!!
[edited by - Shadow_0f_Light on April 20, 2003 12:04:07 AM]
int setCheckTexture(void){ int texWidth = 256; int texHeight = 256; GLubyte *texPixels, *p; int texSize; int i, j; int radius; texSize = texWidth*texHeight*4*sizeof(GLubyte); texPixels = (GLubyte *) malloc(texSize); if (texPixels == NULL) { return false; } p = texPixels; for (i=0; i<texHeight; ++i) { for (j=0; j<texWidth; ++j) { double dist = hypot(float(i - (texHeight / 2)),float(j - (texWidth / 2))); float color = 255-(dist*1.8); if (color < 0) color = 0; p[0] = color; p[1] = color; p[2] = color; p[3] = color; p+=4; } } glBindTexture(GL_TEXTURE_2D, texture[x]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texPixels); free(texPixels); return true;}
in your texture loading function notice I added glBindTexture(GL_TEXTURE_2D, texture[x]); this links the texture you making with texture[x] so no when you call glBindTexture before a polygon it know what texture to use. You can have as many different textures as you want just make sure to change the variable... texture[0], texture[1]... etc... hope that helps!!
[edited by - Shadow_0f_Light on April 20, 2003 12:04:07 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement