use of org.lwjgl.test.opengles.util.ShaderProgram in project lwjgl by LWJGL.
the class Gears method init.
/**
*
*/
private void init() throws LWJGLException {
final int WIDTH = 640;
final int HEIGHT = 480;
Display.setLocation((Display.getDisplayMode().getWidth() - WIDTH) / 2, (Display.getDisplayMode().getHeight() - HEIGHT) / 2);
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
} catch (PowerManagementEventException e) {
e.printStackTrace();
}
Display.setTitle("Gears");
Display.create(new PixelFormat());
//glCoverageMaskNV(true);
// setup ogl
glViewport(0, 0, WIDTH, HEIGHT);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
final Vector3f lp = new Vector3f(5.0f, 5.0f, 10.0f);
lp.normalise();
glLight(GL_LIGHT0, GL_POSITION, lp.getX(), lp.getY(), lp.getZ(), 0.0f);
/* make the gears */
gear1 = new Gear(gear(1.0f, 4.0f, 1.0f, 20, 0.7f), new float[] { 0.8f, 0.1f, 0.0f, 1.0f });
gear2 = new Gear(gear(0.5f, 2.0f, 2.0f, 10, 0.7f), new float[] { 0.0f, 0.8f, 0.2f, 1.0f });
gear3 = new Gear(gear(1.3f, 2.0f, 0.5f, 10, 0.7f), new float[] { 0.2f, 0.2f, 1.0f, 1.0f });
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
final float h = (float) 300 / (float) 300;
glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -40.0f);
vsh = new Shader(GL_VERTEX_SHADER, "uniform highp vec4 LIGHT_POS;\n" + "uniform highp mat4 MODEL_VIEW_PROJECTION_MATRIX;\n" + "uniform mediump mat3 NORMAL_MATRIX;\n" + "uniform lowp vec3 GEAR_COLOR;\n" + "attribute highp vec3 vPosition;\n" + "attribute mediump vec3 vNormal;\n" + "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_Position = MODEL_VIEW_PROJECTION_MATRIX * vec4(vPosition, 1.0);\n" + "\tvec3 normal = NORMAL_MATRIX * vNormal;\n" + "\tcolor = max(dot(normal, vec3(LIGHT_POS)), 0.0) * GEAR_COLOR + vec3(0.05);\n" + "}");
fsh = new Shader(GL_FRAGMENT_SHADER, "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_FragColor = vec4(color, 1.0);\n" + "}");
program = new ShaderProgram(vsh, fsh);
program.enable();
LIGHT_POS = program.getUniformLocation("LIGHT_POS");
MVP = program.getUniformLocation("MODEL_VIEW_PROJECTION_MATRIX");
NM = program.getUniformLocation("NORMAL_MATRIX");
GEAR_COLOR = program.getUniformLocation("GEAR_COLOR");
vPosition = program.getAttributeLocation("vPosition");
vNormal = program.getAttributeLocation("vNormal");
glEnableVertexAttribArray(vNormal);
glEnableVertexAttribArray(vPosition);
}
Aggregations