Archived

This topic is now archived and is closed to further replies.

Scaling Problem

Recommended Posts

I've being having a problem with openGL. I'm a newbie so I wanted to know if someone could help. I have a particle engine that I have working but when I change my perspective using gluPerspective then the size of the flame remains the same despite me using glScale to change it. Also the transparency effects I was using are all screwed up now. Before it would draw a cube and show the flame coming out of the top of the cube. Now the cube is transparent or something. It's weird. If someone can help me out her I would really appreciate it. Here's some of the code I'm using:
static float theta = 0;
// OpenGL animation code

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
theta++;

gluLookAt(cos(DegRad(theta)) * 5, 0, sin(DegRad(theta)) * 5, 0, 0, 0, 0, 1, 0);
glScalef(.5, .5, .5);
glColor4f(1, 1, 1, 1);
glBindTexture(GL_TEXTURE_2D, crate);
glDisable(GL_BLEND);
//Render cube here

glEnd();

//start particle, num of particles, size x, size y, size z

ParticleEffect(0, MAX_PARTICLES, 0.5f, 0.5f, 0.5f);

SwapBuffers( hDC );

--The glass is neither half empty nor half full it just has water in it so get a refill if you need to-- [edited by - DORKUS on August 8, 2003 11:57:54 PM] [edited by - DORKUS on August 9, 2003 2:45:19 PM]

Share on other sites
I've also being able to find out that the blending get's messed up when I use glOrtho as well as gluPerspective. If this helps at all. I also noticed that the flame(Particle Effect) is distorted as well. When the transperency is screwed up and shows part of the flame the part inside the box is larger then the part outside of the box. Here's my particle effect code if you think that might help.

float mat[16];int loop;glGetFloatv(GL_MODELVIEW_MATRIX, mat);glPushAttrib(GL_COLOR_BUFFER_BIT);glPushAttrib(GL_DEPTH_BUFFER_BIT);glPushAttrib(GL_ENABLE_BIT);glEnable(GL_DEPTH_TEST);glDepthMask(GL_TRUE);glEnable(GL_BLEND);glBlendFunc(GL_ONE,GL_ONE);glDepthMask(GL_FALSE);glPushMatrix();glLoadIdentity();glScalef(w, l, d);//Load all positions and sort//Note: the following code is rigged to make the quads always face the userfor(loop = start; loop<start+num;loop++){pos[loop].index = loop;pos[loop].x = mat[0] * particles[loop].x + mat[4] * particles[loop].y + mat[8] * particles[loop].z + mat[12];pos[loop].y = mat[1] * particles[loop].x + mat[5] * particles[loop].y + mat[9] * particles[loop].z + mat[13];pos[loop].z = mat[2] * particles[loop].x + mat[6] * particles[loop].y + mat[10] * particles[loop].z + mat[14];}qsort(&pos, 4, sizeof(POS), ParticleCompare);glBindTexture(GL_TEXTURE_2D, particle_texture);for (loop=start;loop<start+num;loop++)		// Loop Through All The Particles{	if (particles[loop].active)					// If The particles Is Active	{	float x = pos[loop].x;	float y = pos[loop].y;	float z = pos[loop].z;	int index = pos[loop].index;	// Change the color based off the temperature a.k.a. the life of the particle	glColor4f(1-particles[loop].life, particles[loop].life/8+.125,particles[loop].life/16,particles[loop].life);	glPushMatrix();	glTranslatef(x, y, z);	glBegin(GL_TRIANGLE_STRIP);				// Build Quad From A Triangle Strip	glTexCoord2d(1,1); glVertex3f(0.5f,0.5f,0);	glTexCoord2d(0,1); glVertex3f(-0.5f,0.5f,0);	glTexCoord2d(1,0); glVertex3f(0.5f,-0.5f,0);	glTexCoord2d(0,0); glVertex3f(-0.5f,-0.5f,0);	glEnd();	glPopMatrix();	// Move On The X Axis By X Speed	particles[index].x+=particles[index].xi;			// Move On The Y Axis By Y Speed        particles[index].y+=particles[index].yi;	// Move On The Z Axis By Z Speed	particles[index].z+=particles[index].zi;	// Take Pull On X Axis Into Account	particles[index].xi+=particles[index].xg;			// Take Pull On Y Axis Into Account       particles[index].yi+=particles[index].yg;			// Take Pull On Z Axis Into Account 	particles[index].zi+=particles[index].zg;			particles[index].life-=particles[index].fade;		// Reduce Particles Life By 'Fade'	if (particles[index].life<0.0f)					// If particles Is Burned Out	{	ParticleSet(index);	}}glPopMatrix();glPopAttrib();glPopAttrib();glPopAttrib();

--The glass is neither half empty nor half full it just has water in it so get a refill if you need to--

[edited by - DORKUS on August 8, 2003 11:58:38 PM]

Share on other sites
still waiting for the part where you change the projection matrix so i can jump on your for not setting it back to modelview before drawing and especially transforming your stuff ,-)

btw.

wouldnt glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT);
be shorter?

this here seems pointless:
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);

also im not sure if this blend function will have any useful results.

dont use those useless strips for quads. it forces you to begin/end for every tiny piece of data and doesnt even save you any vertices compared to quads. even using two triangles and using two more vertices should be faster than calling begin/end all the time (and of course, youre using immediate mode, so there are a million more urgent ways to optimize than caring about what kind of primitive to use).

Share on other sites
Here's the part where I use perspective

glMatrixMode(GL_PROJECTION); // Select The Projection MatrixglLoadIdentity(); // Reset The Projection Matrix// Calculate The Aspect Ratio Of The WindowgluPerspective(45.0f,1,0.1f,100.0f);glMatrixMode(GL_MODELVIEW); // Select The Modelview MatrixglLoadIdentity();

about the stuff for blending I just do that from what I read on another forum and what I read in the red book. Apparently by turning the Depth Mask off then you turn the depth buffer to read only which fixes rendering problems like the flames not being in the right position and stuff. This seams to work fine before I change the perspective but afterwards everything fails. And I don't mind being picked on for my code. I'm just a newbie anyways. And thanks for the tips.

--Life is like a box of chocalates, it makes you fat and slowly kills you--

[edited by - DORKUS on August 9, 2003 3:24:29 PM]

[edited by - DORKUS on August 9, 2003 5:27:58 PM]

Share on other sites
Alright....I think I figured out what I was doing wrong. In my particle code I have a tweak that makes the particles all face the same direction so that when you rotate it the flames don't disappear. To do this I just took the coordinates I wanted and multiplied them by the modelview matrix and then by the projection matrix and then loaded the identity matrix for both the model and proj matrices to make the object flat. This worked before changing the perspective but afterwords it failed. If anyone knows how to do this a better way then please help.

Here's the tweak:
float mat[16];float per[16];int loop;glGetFloatv(GL_MODELVIEW_MATRIX, mat);glGetFloatv(GL_PROJECTION_MATRIX, per);glMatrixMode(GL_PROJECTION);// Select The Projection MatrixglPushMatrix();glLoadIdentity(); // Reset The Projection MatrixglMatrixMode(GL_MODELVIEW);// Select The Modelview MatrixglPushMatrix();glLoadIdentity();	//Load all positions and sortfor(loop = start; loop<start+num;loop++){pos[loop].index = loop;pos[loop].x = mat[0] * particles[loop].x + mat[4] * particles[loop].y + mat[8] * particles[loop].z + mat[12];pos[loop].y = mat[1] * particles[loop].x + mat[5] * particles[loop].y + mat[9] * particles[loop].z + mat[13];pos[loop].z = mat[2] * particles[loop].x + mat[6] * particles[loop].y + mat[10] * particles[loop].z + mat[14];pos[loop].x = per[0] * particles[loop].x + per[4] * particles[loop].y + per[8] * particles[loop].z + per[12];pos[loop].y = per[1] * particles[loop].x + per[5] * particles[loop].y + per[9] * particles[loop].z + per[13];pos[loop].z = per[2] * particles[loop].x + per[6] * particles[loop].y + per[10] * particles[loop].z + per[14];	}qsort(&pos, 4, sizeof(POS), ParticleCompare);

Then I would draw the particles and move them and such.

--Life is like a box of chocalates, it makes you fat and slowly kills you--

[edited by - DORKUS on August 9, 2003 5:49:50 PM]

• Forum Statistics

• Total Topics
628379
• Total Posts
2982344

• 10
• 9
• 15
• 24
• 11