Skip to main content
gamedev.net
🔒 Locked

problem w/ blending

Started by Wizumwalt 2 replies 850+ views
Original Post
Wizumwalt
Wizumwalt
Hi, I'm having a problem learning how to do blending. I have drawn my model in the center of the canvas, then I translate to the lower left corner and try to draw a small black semi-transparent rectangle and then I draw my x, y, and z axis (on top?) to show the direction that the model is rotated in. My problem is that, I can't figure out how to shade the part of the model that should be behind the rectangle so that the axis shows up better, and the other problem is that the rectangle clips the part of my rotation axis that is behind it. Of course if I remove gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL), then x, y, and z in front of the GL_FILL on the axis shows up fine, but ... I still have the transparency problem. Can anyone help with what I'm doing wrong?

public void init(GLAutoDrawable drawable) {
	...
	gl.glEnable(GL.GL_BLEND);
	gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
	...
}

public void display(GLAutoDrawable drawable) {
	...
	// draw model here
        ...

        // draw transparent pane and axis
	gl.glLoadIdentity();
					
	gl.glTranslatef((float) (-(height / 2) * 0.8), (float) -((height / 2) * 0.8), 0.0f);
	drawTransparentPane(drawable, viewPort);
							
	gl.glMultMatrixf(transf);
	drawAxis(drawable, viewPort);
	...
}

public void drawTransparentPane(GLAutoDrawable drawable, ViewPort viewPort) {
	GL gl = drawable.getGL();
	gl.glColor3f(0.0f, 0.0f, 0.0f);
	gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);

	gl.glBegin(GL.GL_POLYGON);
		gl.glVertex3f((float) -((viewPort.width / 2) * .2), (float) -((viewPort.height / 2) * .2), 0.0f);
		gl.glVertex3f((float) -((viewPort.width / 2) * .2), (float) ((viewPort.height / 2) * .2), 0.0f);
		gl.glVertex3f((float) ((viewPort.width / 2) * .2), (float) ((viewPort.height / 2) * .2), 0.0f);
		gl.glVertex3f((float) ((viewPort.width / 2) * .2), (float) -((viewPort.height / 2) * .2), 0.0f);
	gl.glEnd();
}

public void drawAxis(GLAutoDrawable drawable, ViewPort viewPort) {
	// draw x, y, and z lines
}
ennetws
ennetws
Have you tried:

gl.glColor4f(red, green, blue, transperncy);

instead of just 'gl.glColor3f' ?

Hope that helps.
Wizumwalt
Wizumwalt
Quote:
Original post by ennetws
Have you tried:

gl.glColor4f(red, green, blue, transperncy);


Actually, I just saw that before I read your reply, and made the following changes, but this didn't help.

I think it has something to do w/ the way I draw the rectangle. The only way I can get a solid filled rectangle is using gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL), but this hides the part of the axis that rotates behind the plane (backside of the rectangle face). Otherwise, without it, I just see a 'lined' box and not filled.

public void drawTransparentPane(GLAutoDrawable drawable, ViewPort viewPort) {	GL gl = drawable.getGL();	gl.glColor4f(0.0f, 0.0f, 0.0f, 0.5f);	gl.glBegin(GL.GL_POLYGON);		gl.glVertex3f((float) -((viewPort.width / 2) * .2), (float) -((viewPort.height / 2) * .2), 0.0f);		gl.glVertex3f((float) -((viewPort.width / 2) * .2), (float) ((viewPort.height / 2) * .2), 0.0f);		gl.glVertex3f((float) ((viewPort.width / 2) * .2), (float) ((viewPort.height / 2) * .2), 0.0f);		gl.glVertex3f((float) ((viewPort.width / 2) * .2), (float) -((viewPort.height / 2) * .2), 0.0f);	gl.glEnd();}
Kalidor
Kalidor
What you are doing is a little off from what you seem to be describing. I think what you want to do is the following

- disable blending and enable depth testing
- render model
- enable blending and disable depth testing
- render transparent quad
- optionally disable blending if you don't want the axes themselves to be blended
- render axes

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.