List of usage examples for org.lwjgl.opengl GL11 GL_AMBIENT
int GL_AMBIENT
To view the source code for org.lwjgl.opengl GL11 GL_AMBIENT.
Click Source Link
From source file:com.ardor3d.scene.state.lwjgl.LwjglLightStateUtil.java
License:Open Source License
private static void setAmbient(final int index, final LightStateRecord record, final ReadOnlyColorRGBA ambient, final LightRecord lr) { if (!record.isValid() || !lr.ambient.equals(ambient)) { record.lightBuffer.clear();//from w w w .ja va 2s. c o m record.lightBuffer.put(ambient.getRed()); record.lightBuffer.put(ambient.getGreen()); record.lightBuffer.put(ambient.getBlue()); record.lightBuffer.put(ambient.getAlpha()); record.lightBuffer.flip(); GL11.glLight(GL11.GL_LIGHT0 + index, GL11.GL_AMBIENT, record.lightBuffer); lr.ambient.set(ambient); } }
From source file:com.ardor3d.scene.state.lwjgl.LwjglMaterialStateUtil.java
License:Open Source License
/** * Converts the color material setting of this state to a GL constant. * /*from w w w . j ava 2 s. c om*/ * @return the GL constant */ private static int getGLColorMaterial(final ColorMaterial material) { switch (material) { case None: return GL11.GL_NONE; case Ambient: return GL11.GL_AMBIENT; case Diffuse: return GL11.GL_DIFFUSE; case AmbientAndDiffuse: return GL11.GL_AMBIENT_AND_DIFFUSE; case Emissive: return GL11.GL_EMISSION; case Specular: return GL11.GL_SPECULAR; } throw new IllegalArgumentException("invalid color material setting: " + material); }
From source file:com.gameminers.ethereal.architect.ModelCanvas.java
License:Open Source License
@Override protected void paintGL() { try {/*from w ww .ja v a 2 s . c om*/ if (getWidth() != current_width || getHeight() != current_height) { current_width = getWidth(); current_height = getHeight(); GL11.glViewport(0, 0, current_width, current_height); } GL11.glClearColor(0.0f, 0.6f, 0.5f, 1.0f); GL11.glClearDepth(1.0); GL11.glColor3f(1, 1, 1); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glLoadIdentity(); GLU.gluPerspective(45.0f, (float) getWidth() / (float) getHeight(), 0.1f, 1000.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glTranslatef(0, 0, zoom); GL11.glRotatef(angle, 0f, 1f, 0f); GL11.glRotatef(tilt, 1f, 0f, 0f); GL11.glTranslatef(-16, -16, -16); if (lit) { GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHT0); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, lightPosition); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, lightAmbient); } else { GL11.glDisable(GL11.GL_LIGHTING); } if (textured) { GL11.glEnable(GL11.GL_TEXTURE_2D); } else { GL11.glDisable(GL11.GL_TEXTURE_2D); } if (model != null) { if (model.isAmbientOcclusionEnabled()) { GL11.glShadeModel(GL11.GL_SMOOTH); } else { GL11.glShadeModel(GL11.GL_FLAT); } for (ModelElement ele : model.getElements()) { GL11.glPushMatrix(); if (ele.isShade()) { GL11.glEnable(GL11.GL_LIGHTING); } else { GL11.glDisable(GL11.GL_LIGHTING); } float fromX = ele.getFrom()[0]; float fromY = ele.getFrom()[1]; float fromZ = ele.getFrom()[2]; float toX = ele.getTo()[0]; float toY = ele.getTo()[1]; float toZ = ele.getTo()[2]; float fX = (fromX > toX ? fromX : toX); float fY = (fromY > toY ? fromY : toY); float fZ = (fromZ > toZ ? fromZ : toZ); float tX = (fromX > toX ? toX : fromX); float tY = (fromY > toY ? toY : fromY); float tZ = (fromZ > toZ ? toZ : fromZ); GL11.glTranslatef(fX, fY, fZ); float scaleX = tX - fX; float scaleY = tY - fY; float scaleZ = tZ - fZ; GL11.glBegin(GL11.GL_QUADS); GL11.glNormal3f(0, 0, -1f); for (int i = 0; i < vertices.length / 3; i++) { int faceIdx = i / 4; ModelFace face; switch (faceIdx) { case 0: face = ele.getFaces().getNorth(); break; case 1: face = ele.getFaces().getSouth(); break; case 2: face = ele.getFaces().getUp(); break; case 3: face = ele.getFaces().getDown(); break; case 4: face = ele.getFaces().getWest(); break; case 5: face = ele.getFaces().getEast(); break; default: face = null; break; } int idx = i * 3; float vX = vertices[idx] * scaleX; float vY = vertices[idx + 1] * scaleY; float vZ = vertices[idx + 2] * scaleZ; /*float u; float v; GL11.glTexCoord2f(u, v);*/ GL11.glVertex3f(vX, vY, vZ); } GL11.glEnd(); GL11.glPopMatrix(); } } GL11.glPopMatrix(); swapBuffers(); repaint(); } catch (LWJGLException e) { throw new RuntimeException(e); } }
From source file:com.owens.oobjloader.Main.java
License:BSD License
/** * Runs the program (the "main loop")//from w w w.java2 s. c om */ private static void run(String filename, String defaultTextureMaterial) { DisplayModel scene = null; scene = new DisplayModel(); log.log(INFO, "Parsing WaveFront OBJ file"); Build builder = new Build(); Parse obj = null; try { obj = new Parse(builder, filename); } catch (java.io.FileNotFoundException e) { log.log(SEVERE, "Exception loading object! e=" + e); e.printStackTrace(); } catch (java.io.IOException e) { log.log(SEVERE, "Exception loading object! e=" + e); e.printStackTrace(); } log.log(INFO, "Done parsing WaveFront OBJ file"); log.log(INFO, "Splitting OBJ file faces into list of faces per material"); ArrayList<ArrayList<Face>> facesByTextureList = createFaceListsByMaterial(builder); log.log(INFO, "Done splitting OBJ file faces into list of faces per material, ended up with " + facesByTextureList.size() + " lists of faces."); TextureLoader textureLoader = new TextureLoader(); int defaultTextureID = 0; if (defaultTextureMaterial != null) { log.log(INFO, "Loading default texture =" + defaultTextureMaterial); defaultTextureID = setUpDefaultTexture(textureLoader, defaultTextureMaterial); log.log(INFO, "Done loading default texture =" + defaultTextureMaterial); } if (defaultTextureID == -1) { BufferedImage img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); Graphics g = img.getGraphics(); g.setColor(Color.BLUE); g.fillRect(0, 0, 256, 256); g.setColor(Color.RED); for (int loop = 0; loop < 256; loop++) { g.drawLine(loop, 0, loop, 255); g.drawLine(0, loop, 255, loop); } defaultTextureID = textureLoader.convertToTexture(img); } int currentTextureID = -1; for (ArrayList<Face> faceList : facesByTextureList) { if (faceList.isEmpty()) { log.log(INFO, "ERROR: got an empty face list. That shouldn't be possible."); continue; } log.log(INFO, "Getting material " + faceList.get(0).material); currentTextureID = getMaterialID(faceList.get(0).material, defaultTextureID, builder, textureLoader); log.log(INFO, "Splitting any quads and throwing any faces with > 4 vertices."); ArrayList<Face> triangleList = splitQuads(faceList); log.log(INFO, "Calculating any missing vertex normals."); calcMissingVertexNormals(triangleList); log.log(INFO, "Ready to build VBO of " + triangleList.size() + " triangles"); ; if (triangleList.size() <= 0) { continue; } log.log(INFO, "Building VBO"); VBO vbo = VBOFactory.build(currentTextureID, triangleList); log.log(INFO, "Adding VBO with text id " + currentTextureID + ", with " + triangleList.size() + " triangles to scene."); scene.addVBO(vbo); } log.log(INFO, "Finally ready to draw things."); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHT0); GL11.glEnable(GL11.GL_LIGHT1); float lightAmbient[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float lightDiffuse[] = { 0.5f, 0.5f, 1.0f, 1.0f }; float lightSpecular[] = { 0.0f, 1.0f, 1.0f, 0.0f }; GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, asFloatBuffer(lightAmbient)); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, asFloatBuffer(lightDiffuse)); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, asFloatBuffer(lightSpecular)); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, asFloatBuffer(lightAmbient)); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, asFloatBuffer(lightDiffuse)); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR, asFloatBuffer(lightSpecular)); float lightPosition0[] = { posix, posiy, posiz, 1.0f }; GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, asFloatBuffer(lightPosition0)); float lightPosition1[] = { posix, posiy, posizz, 1.0f }; GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, asFloatBuffer(lightPosition1)); while (!finished) { GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GLU.gluLookAt(orix, oriy, oriz, cenx, ceny, cenz, 0, 1, 0); // rotate(based on camera) GL11.glRotatef(rotateSee, 0, 1, 0); GL11.glRotatef(rotateSeeAnother, 1, 0, 0); // transform GL11.glTranslated(0, -0.75, -2); // rotate(based on model) GL11.glRotatef(rotate, 0, 1, 0); GL11.glRotatef(rotateAnother, 1, 0, 0); // Always call Window.update(), all the time - it does some behind the // scenes work, and also displays the rendered output Display.update(); // Check for close requests if (Display.isCloseRequested()) { finished = true; } // The window is in the foreground, so render! else if (Display.isActive()) { logic(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); scene.render(); Display.sync(FRAMERATE); } // The window is not in the foreground, so we can allow other stuff to run and infrequently update else { try { Thread.sleep(100); } catch (InterruptedException e) { } logic(); // Only bother rendering if the window is visible or dirty if (Display.isVisible() || Display.isDirty()) { System.err.print("."); scene.render(); } } } }
From source file:com.runescape.client.revised.editor.modelviewer.Viewport.java
License:Open Source License
public void render() { final Dimension size = this.canvas.getSize(); if ((size.width > 0) && (size.height > 0)) { if ((this.width != size.width) || (this.height != size.height)) { this.width = size.width; this.height = size.height; GL11.glViewport(0, 0, this.width, this.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity();/*from w w w .j av a 2s .c o m*/ final float c = (float) Math .sqrt((double) (this.width * this.width) + (double) (this.height * this.height)); GL11.glOrtho(0.0F, this.width, 0.0F, this.height, -c, c); GL11.glMatrixMode(GL11.GL_MODELVIEW); final boolean useShader = this.initShader(); if (ModelConstants.ENABLE_VERTEX_SHADER && useShader) { ARBShaderObjects.glUseProgramObjectARB(this.program); } if (ModelConstants.ENABLE_LIGHTING) { GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHT0); final FloatBuffer diffuse = BufferUtils.createFloatBuffer(4) .put(new float[] { 1F, 1F, 1F, 1F }); final FloatBuffer position = BufferUtils.createFloatBuffer(4) .put(new float[] { 3F, 0F, 1F, 0F }); final FloatBuffer ambient = BufferUtils.createFloatBuffer(4) .put(new float[] { .1F, .1F, .2F, .3F }); final FloatBuffer specular = BufferUtils.createFloatBuffer(4) .put(new float[] { 1F, 1F, 1F, 1F }); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, (FloatBuffer) specular.flip()); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, (FloatBuffer) ambient.flip()); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, (FloatBuffer) diffuse.flip()); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, (FloatBuffer) position.flip()); GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 50.0f); } } if (Mouse.isButtonDown(0) && !Mouse.isButtonDown(1)) { this.yaw -= Mouse.getDX(); this.pitch -= Mouse.getDY(); } if (Mouse.isButtonDown(0) && Mouse.isButtonDown(1)) { this.offset_z += Mouse.getDY(); } float wheel = Mouse.getDWheel() / 960.0F; if (wheel > 1.0F) { wheel = 1.0F; } else if (wheel < -1.0F) { wheel = -1.0F; } this.scale -= this.scale * wheel; if (this.scale < 0.01F) { this.scale = 0.01F; } for (final Model3D dragonModel : this.getDragonList()) { final float x = this.width / 1.2F; final float y = (-((100.0F * (this.scale))) + (this.offset_z + 0.1F)) + ((this.height - dragonModel.height()) / 2.0F); final float z = 0.0F; dragonModel.calcDimms(false); dragonModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } for (final Model3D torvaModel : this.getTorvaList()) { final float x = this.width / 1.7F; final float y = (-((100.0F * (this.scale))) + this.offset_z) + ((this.height - torvaModel.height()) / 2.0F); final float z = 0.0F; torvaModel.calcDimms(false); torvaModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } for (final Model3D jadModel : this.getJadList()) { final float x = this.width / 3.2F; final float y = (-((100.0F * (this.scale))) + this.offset_z) + ((this.height - jadModel.height()) / 2.0F); final float z = 0.0F; jadModel.calcDimms(false); jadModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } for (final Model3D trollModel : this.getTrollList()) { final float x = this.width / 3.8F; final float y = (-((100.0F * (this.scale))) + this.offset_z) + ((this.height - trollModel.height()) / 2.0F); final float z = 0.0F; trollModel.calcDimms(false); trollModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } if (ModelConstants.ENABLE_VERTEX_SHADER && this.initShader()) { ARBShaderObjects.glUseProgramObjectARB(0); } Display.update(); } }
From source file:com.rvantwisk.cnctools.controls.opengl.BeadActor.java
License:Open Source License
@Override public void initialize() { ambient = allocFloats(colorDefaultDiffuse); diffuse = allocFloats(colorDefaultDiffuse); specular = allocFloats(colorDefaultSpecular); shininess = allocFloats(new float[] { 32.0f, 0.0f, 0.0f, 0.0f }); light = allocFloats(colorDefaultLight); lightPos0 = allocFloats(lightDefaultPos0); lightPos1 = allocFloats(lightDefaultPos1); display_list = GL11.glGenLists(1);/*from ww w. jav a 2 s . co m*/ GL11.glNewList(display_list, GL11.GL_COMPILE); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHT0); GL11.glEnable(GL11.GL_LIGHT1); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, ambient); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, diffuse); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, specular); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SHININESS, shininess); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, light); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, light); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, light); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, lightPos0); GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, lightPos1); GL11.glColor3f(1.0f, 0.0f, 0.0f); Sphere s = new Sphere(); s.setDrawStyle(GLU.GLU_FILL); s.setNormals(GLU.GLU_SMOOTH); s.draw(3.8f, 100, 100); GL11.glDisable(GL11.GL_LIGHT1); GL11.glDisable(GL11.GL_LIGHT0); GL11.glDisable(GL11.GL_LIGHTING); GL11.glEndList(); }
From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java
License:Open Source License
@Override public void setMaterialAmbientColor(float[] color) { GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, getDirectBuffer(color)); }
From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java
License:Open Source License
@Override public void setLightAmbientColor(int light, float[] color) { GL11.glLight(GL11.GL_LIGHT0 + light, GL11.GL_AMBIENT, getDirectBuffer(color)); }
From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java
License:Open Source License
private void setColor(float r, float g, float b, float alpha) { //GLfloat light_ambient[4],light_diffuse[4],light_specular[4]; light_ambient2.put(new float[] { r * 0.3f, g * 0.3f, b * 0.3f, alpha }).flip(); light_diffuse2.put(new float[] { r * 0.7f, g * 0.7f, b * 0.7f, alpha }).flip(); light_specular2.put(new float[] { r * 0.2f, g * 0.2f, b * 0.2f, alpha }).flip(); GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT, light_ambient2); GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_DIFFUSE, light_diffuse2); GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_SPECULAR, light_specular2); GL11.glMaterialf(GL11.GL_FRONT_AND_BACK, GL11.GL_SHININESS, 5.0f); }
From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java
License:Open Source License
@Override // void dsDrawFrame (int width, int height, dsFunctions *fn, int pause) void dsDrawFrame(int width, int height, dsFunctions fn, boolean pause) { if (current_state < 1) dsDebug("internal error"); current_state = 2;/* www. j a v a 2 s.c o m*/ // setup stuff GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHT0); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_TEXTURE_GEN_S); GL11.glDisable(GL11.GL_TEXTURE_GEN_T); GL11.glShadeModel(GL11.GL_FLAT); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glCullFace(GL11.GL_BACK); GL11.glFrontFace(GL11.GL_CCW); // setup viewport GL11.glViewport(0, 0, width, height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); final float vnear = 0.1f; final float vfar = 100.0f; final float k = 0.8f; // view scale, 1 = +/- 45 degrees if (width >= height) { float k2 = (float) height / (float) width; GL11.glFrustum(-vnear * k, vnear * k, -vnear * k * k2, vnear * k * k2, vnear, vfar); } else { float k2 = (float) width / (float) height; GL11.glFrustum(-vnear * k * k2, vnear * k * k2, -vnear * k, vnear * k, vnear, vfar); } // setup lights. it makes a difference whether this is done in the // GL_PROJECTION matrix mode (lights are scene relative) or the // GL_MODELVIEW matrix mode (lights are camera relative, bad!). // static GLfloat light_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; // static GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; // static GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, light_ambient); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, light_diffuse); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, light_specular); GL11.glColor3f(1.0f, 1.0f, 1.0f); // clear the window GL11.glClearColor(0.5f, 0.5f, 0.5f, 0); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // snapshot camera position (in MS Windows it is changed by the GUI thread) float[] view2_xyz = view_xyz.clone(); float[] view2_rxyz = view_rxyz.clone(); // memcpy (view2_xyz,view_xyz);//,sizeof(float)*3); // memcpy (view2_hpr,view_hpr);//,sizeof(float)*3); // go to GL_MODELVIEW matrix mode and set the camera GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); setCamera(view2_xyz[0], view2_xyz[1], view2_xyz[2], view2_rxyz[0], view2_rxyz[1], view2_rxyz[2]); // set the light position (for some reason we have to do this in model view. // static GLfloat light_position[] = { LIGHTX, LIGHTY, 1.0, 0.0 }; GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, light_position); // draw the background (ground, sky etc) drawSky(view2_xyz); drawGround(); // draw the little markers on the ground drawPyramidGrid(); // leave openGL in a known state - flat shaded white, no textures GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_FLAT); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glColor3f(1, 1, 1); setColor(1, 1, 1, 1); // draw the rest of the objects. set drawing state first. color[0] = 1; color[1] = 1; color[2] = 1; color[3] = 1; tnum = DS_TEXTURE_NUMBER.DS_NONE; //if (fn.step) fn.step(pause); }