Game Development Community

Drawing blending lines

by Daniel Buckmaster · in Torque Game Engine · 03/31/2008 (9:58 am) · 0 replies

This should probably be in the OpenGL forum, but there's not much activity over there.

I'm modifying Blake LaPierre's bullet tracer resource to support colour and alpha blending. So you specify two colours for the tracer line, with alpha values, and the tracers will be drawn with the first colour at one vertex and the second at the other vertex. Simple, right?
Would be if I knew the first thing about OpenGL.
I've got colour blending working, but what I don't understand is why alpha blending is not going on. Here's my modified render code (part of Projectile::renderObject):
if (mDataBlock->tracerLength > 0)
	{
		Point3F end = mCurrVelocity;
		end.normalize(mClampF((mCurrPosition - mInitialPosition).len(), 1.0, mDataBlock->tracerLength));

		if(mDataBlock->tracerWidth > 0)
			glLineWidth(mDataBlock->tracerWidth);
		else
			glLineWidth(0.5);

		glBegin(GL_LINES);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glColor4fv(mDataBlock->tracerStartColor);
		glVertex3f(mCurrPosition.x, mCurrPosition.y, mCurrPosition.z);

		end = mCurrPosition - end;
		glColor4fv(mDataBlock->tracerEndColor);
		glVertex3f(end.x, end.y, end.z);

		glDisable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ZERO);
		glEnd();
		glLineWidth(.1f);
	}
I've debugged, and all the values (like tracerEndColour) are correct.

The other problem I have is that if the tracer is rendered close to the camera, it is flat black. Only when I move the camera away (quite a long way) do the datablock colours kick in. Did I break something?

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!