Frame rate too low! Why?

Hello…

I have a solid, transparent triangle using blending that rotates around its own axis.
But when I make it transparent it totates MUCH slower than normally, even when I try to increase the rotation counter. Here is the code I use (I just copied and pasted it from MSVC++5):

//===========
//Comment these 4 lines to use blending (transparency)
//===========
glEnable(GL_BLEND); // Enable Blending
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Type Of Blending To Perform
//This gives weird results:
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glDisable(GL_DEPTH_TEST);	// Turn Depth Testing Off - Required for blending!
glColor4f(1.0f,1.0f,1.0f,0.5f);			// Full Brightness, 50% Alpha ( NEW )
//===========
//End blending (transparency)
//===========

Well I don’t use alpha, but I know that it is more expensive to calculate, don’t know if there is abetter way of doing it. Try changing the res your running it at.

gav

there are many ways to optimize, first of all : Are you calling the glBlendfunc, glColor glDisable() every time u draw the triangle ?

Did u try to use glVertex3fv() or d or i ??

It’s not always needed to disable depth test when drawing blended polys also.

Cya

I have the following code for in DrawGLScene, so you can see everything that I use:

int DrawGLScene(GLvoid) // Here’s Where We Do All The Drawing
{
/Daniel: Here is the ‘magic’ part of our code.
Here is where we draw the objects that we want
/
//Begin OLD code
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
//End OLD code

//=======================
//MOVE DRAWING BRUSH (ORIGINALLY FIRST VAR WAS -1.5f)
//=======================
glTranslatef(0.0f,0.0f,-6.0f);					// Move Left 1.5 Units And Into The Screen 6.0

//=======================
//ROTATE TRIANGLE
//=======================

glRotatef(rtri,0.0f,1.0f,0.0f);				// Rotate The Triangle On The Y axis ( NEW )



glBegin(GL_TRIANGLES);	// Drawing Using Triangles
		
glColor3f(1.0f,0.0f,0.0f);			// Red
	glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
	glColor3f(0.0f,1.0f,0.0f);			// Green
	glVertex3f(-1.0f,-1.0f, 1.0f);			// Left Of Triangle (Front)
	glColor3f(0.0f,0.0f,1.0f);			// Blue
	glVertex3f( 1.0f,-1.0f, 1.0f);			// Right Of Triangle (Front)


	glColor3f(1.0f,0.0f,0.0f);			// Red
	glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
	glColor3f(0.0f,0.0f,1.0f);			// Blue
	glVertex3f( 1.0f,-1.0f, 1.0f);			// Left Of Triangle (Right)
	glColor3f(0.0f,1.0f,0.0f);			// Green
	glVertex3f( 1.0f,-1.0f, -1.0f);			// Right Of Triangle (Right)

  glColor3f(1.0f,0.0f,0.0f);			// Red
	glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
	glColor3f(0.0f,1.0f,0.0f);			// Green
	glVertex3f( 1.0f,-1.0f, -1.0f);			// Left Of Triangle (Back)
	glColor3f(0.0f,0.0f,1.0f);			// Blue
	glVertex3f(-1.0f,-1.0f, -1.0f);			// Right Of Triangle (Back)

   glColor3f(1.0f,0.0f,0.0f);			// Red
	glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
	glColor3f(0.0f,0.0f,1.0f);			// Blue
	glVertex3f(-1.0f,-1.0f,-1.0f);			// Left Of Triangle (Left)
	glColor3f(0.0f,1.0f,0.0f);			// Green
	glVertex3f(-1.0f,-1.0f, 1.0f);			// Right Of Triangle (Left)


glEnd();							// Finished Drawing The Triangle

//=======================
//ADD 0.9 TO ROTATE OUR TRIANGLE
//=======================
rtri+=0.9f;						// Increase The Rotation Variable For The Triangle ( NEW )



return TRUE;								// Everything Went OK

}

What’s your graphic card? It might be that the card/driver don’t support that blending mode so you get a software renderer.

I have an Ati Rage pro 3D, and a guillemot maxi gamer 3d2 (voodo2).

I have a Voodoo3 3000 (3Dfx now has full OpenGL support; get the reference drivers everybody!!!) and I think that your code should run fine. I have done stuff somewhat like that… Perhaps you’re initializing something wrong? If you have any anti-aliasing or anything REALLY expensive enabled, try turning it off. Also, the depth buffer should be off when doing blending, because suppose you draw the closer object first… then the farther one that is drawn later becomes the clear color. (black by default) I could use Z ordering (But how… anyone? I use VB6 to do most of my OpenGL, but I’m starting to use VC++, pick one ) Why are you using glLoadIdentity() every time you draw a new frame? I’m clueless on that, but remember that I’m somewhat new to all this; Im not really of any help in the way of speed as I love blending stuff, and texturing stuff, and bilinear filtering it, etc…

PS - Set your blending mode to GL_ONE, GL_SRC_ALPHA. I think it looks pretty cool, but I don’t have my source anymore, so I can’t remember if that’s right. Put GL_ONE first for light blends, and something else first for darker blends, and use GL_ONE second for all-black effects

Thanks for the help everyone…

I don’t quite know why I used this. I looked at NeHes opengl tutorials and used that code in my own project.

Anyone else used NeHes tuts to get blending to work without a frame rate drop?