/* Copyright 2010-2011 Christian Matt
*
* This file is part of PonkOut.
*
* PonkOut is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PonkOut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PonkOut. If not, see <http://www.gnu.org/licenses/>.
*/
package ponkOut.graphics;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import ponkOut.graphics.resources.Shader;
import ponkOut.graphics.resources.ShaderManager;
import ponkOut.logic.Ball;
public class GlowingBallGO extends BallGO {
private static Shader ballGlowVShader = ShaderManager.getInstance().getShader("ballGlow.arbvp1");
private static Shader ballGlowFShader = ShaderManager.getInstance().getShader("ballGlow.arbfp1");
private int displayList;
public GlowingBallGO(Ball ball, float red, float green, float blue, GraphicsObjectsManager goManager) {
super(ball, new Color(red, green, blue), goManager);
// 2/3 of the ball are glow
float radius = 3.0f * ball.getRadius();
// create display list
displayList = GL11.glGenLists(1);
GL11.glNewList(displayList, GL11.GL_COMPILE);
GL11.glBegin(GL11.GL_QUADS);
// draw back (visible in reflection)
GL11.glVertex3f(-radius, -radius, 0.0f); // bottom left
GL11.glVertex3f(-radius, radius, 0.0f); // top left
GL11.glVertex3f(radius, radius, 0.0f); // top right
GL11.glVertex3f(radius, -radius, 0.0f); // bottom right
// draw front
GL11.glVertex3f(-radius, -radius, 0.0f); // bottom left
GL11.glVertex3f(radius, -radius, 0.0f); // bottom right
GL11.glVertex3f(radius, radius, 0.0f); // top right
GL11.glVertex3f(-radius, radius, 0.0f); // top left
GL11.glEnd();
GL11.glEndList();
}
@Override
public void draw() {
// store current transformation matrix
GL11.glPushMatrix();
// translate to ball position
Vector2f pos = ball.getPosition();
GL11.glTranslatef(pos.x, pos.y, 0.0f);
// set color
appearance.use();
// enable shaders
ballGlowVShader.enable();
ballGlowFShader.enable();
// draw
GL11.glCallList(displayList);
// disable shaders
ballGlowFShader.disable();
ballGlowVShader.disable();
// restore transformation matrix
GL11.glPopMatrix();
}
@Override
public boolean isOpaque() {
return false;
}
}