List of usage examples for org.lwjgl.opengl GL11 glLoadIdentity
public static native void glLoadIdentity();
From source file:com.runescape.client.revised.editor.modelviewer.Model3D.java
License:Open Source License
public void render(final float x, final float y, final float z, final float rx, final float ry, final float rz, final float sx, final float sy, final float sz) { GL11.glLoadIdentity(); GL11.glTranslatef(x, y, z);//w w w. j a v a2s .c o m GL11.glRotatef(rx, 1.0F, 0.0F, 0.0F); GL11.glRotatef(ry, 0.0F, 1.0F, 0.0F); GL11.glRotatef(rz, 0.0F, 0.0F, 1.0F); GL11.glScalef(sx, sy, sz); final short[] tri_x = this.triangle_viewspace_x; final short[] tri_y = this.triangle_viewspace_y; final short[] tri_z = this.triangle_viewspace_z; // final short[] tex_map_x = this.texture_map_x; // final short[] tex_map_y = this.texture_map_y; // final short[] tex_map_z = this.texture_map_z; final short[] textures = this.textures; final int[] vertices_x = this.vertices_x; final int[] vertices_y = this.vertices_y; final int[] vertices_z = this.vertices_z; final short[] colors = this.colors; final float model_scale = 4.0F; final float texture_scale = 1.0F; if (this.pointers != null) { //glEnable(GL_DEPTH_TEST); GL11.glEnable(GL11.GL_TEXTURE_2D); //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } Texture texture = null; for (int triangle = 0; triangle != this.triangle_count; ++triangle) { if ((this.alpha != null) && (this.alpha[triangle] == -1)) { continue; } final int point_a = tri_x[triangle]; final int point_b = tri_y[triangle]; final int point_c = tri_z[triangle]; final int color = Model.hsl2rgb[colors[triangle] & 0xffff]; int triangle_type; if (this.face_fill_attributes == null) { triangle_type = 0; } else { triangle_type = this.face_fill_attributes[triangle] & 3; } if ((textures != null) && (textures[triangle] != -1)) { final int id = textures[triangle] & 0xffff; if (ModelConstants.ENABLE_MODEL_TEXTURES && ((texture == null) && (id != -1))) { texture = TextureCache.get(id); } if (texture != null) { texture.bind(); } } final boolean textured = ModelConstants.ENABLE_MODEL_TEXTURES && (texture != null); GL11.glBegin(GL11.GL_TRIANGLES); GL11.glColor4ub((byte) (color >>> 16), (byte) (color >>> 8), (byte) color, (byte) (this.alpha == null ? 0xff : ~this.alpha[triangle])); switch (triangle_type) { case 0://shaded triangle case 1://flat triangle if (textured) { GL11.glTexCoord2f(0.0F, 0.0F); } GL11.glVertex3f(vertices_x[point_a] / model_scale, vertices_y[point_a] / model_scale, vertices_z[point_a] / model_scale); if (textured) { GL11.glTexCoord2f(0.0F, texture_scale / model_scale); } GL11.glVertex3f(vertices_x[point_b] / model_scale, vertices_y[point_b] / model_scale, vertices_z[point_b] / model_scale); if (textured) { GL11.glTexCoord2f(texture_scale / model_scale, texture_scale / model_scale); } GL11.glVertex3f(vertices_x[point_c] / model_scale, vertices_y[point_c] / model_scale, vertices_z[point_c] / model_scale); break; case 2://textured? case 3://textured? final int ptr = this.face_fill_attributes[triangle] >> 2; final int tex_point_a = this.texture_map_x[ptr]; final int tex_point_b = this.texture_map_y[ptr]; final int tex_point_c = this.texture_map_z[ptr]; GL11.glTexCoord2f(0.0F, 0.0F); GL11.glVertex3f(vertices_x[tex_point_a] / model_scale, vertices_y[tex_point_a] / model_scale, vertices_z[tex_point_a] / model_scale); GL11.glTexCoord2f(0.0F, texture_scale / model_scale); GL11.glVertex3f(vertices_x[tex_point_b] / model_scale, vertices_y[tex_point_b] / model_scale, vertices_z[tex_point_b] / model_scale); GL11.glTexCoord2f(texture_scale / model_scale, texture_scale / model_scale); GL11.glVertex3f(vertices_x[tex_point_c] / model_scale, vertices_y[tex_point_c] / model_scale, vertices_z[tex_point_c] / model_scale); break; } GL11.glEnd(); } if (texture != null) { GL11.glDisable(GL11.GL_TEXTURE_2D); } }
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(); 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); }//from ww w . jav a 2 s. c om 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.opengl.View2D.java
License:Open Source License
@Override public void begin() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix();//from www. ja v a 2 s . c o m GL11.glLoadIdentity(); GL11.glOrtho(0, camera.getWidth(), 0, camera.getHeight(), NEAR, FAR); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); }
From source file:com.rvantwisk.cnctools.opengl.View2D.java
License:Open Source License
@Override public void display_transform() { // _center_on_origin GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(-camera.getX(), camera.getX(), -camera.getY(), camera.getY(), NEAR, FAR); GL11.glMatrixMode(GL11.GL_MODELVIEW); // _center_on_origin GL11.glTranslatef(camera.getX(), camera.getY(), camera.getZ()); GL11.glRotatef(camera.getAzimuth(), 0.0f, 0.0f, 1.0f); GL11.glScalef(camera.getZoom_factor(), camera.getZoom_factor(), camera.getZoom_factor()); }
From source file:com.rvantwisk.cnctools.opengl.View3D.java
License:Open Source License
@Override public void begin() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix();/*from ww w. j a v a 2s . co m*/ GL11.glLoadIdentity(); if (camera.isOrtho()) { GL11.glOrtho(-camera.getX(), camera.getX(), -camera.getY(), camera.getY(), -NEAR, FAR); } else { GLU.gluPerspective(camera.getFOVY(), camera.getWidth() / camera.getHeight(), NEAR, FAR); } GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); }
From source file:com.samrj.devil.graphics.Camera2D.java
public static void glLoadScreen(int resX, int resY) { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0f, resX, 0f, resY, -1f, 1f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity();/*w w w .j a v a 2 s. c o m*/ }
From source file:com.samrj.devil.graphics.Camera2D.java
public static void glLoadIdentity() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }
From source file:com.sriramramani.droid.inspector.ui.InspectorCanvas.java
License:Mozilla Public License
private void doResize() { // Get the aspect ratio. Rectangle bounds = getBounds(); float aspectRatio = (float) bounds.width / (float) bounds.height; // Set current. setCurrent();// w w w.j a v a2 s. c o m // Reset viewport. GL11.glViewport(0, 0, bounds.width, bounds.height); // Set the projection matrix. GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); if (mIsOrtho) { // Changing top and bottom to make it draw in 4th quadrant. GL11.glOrtho(0, bounds.width, bounds.height, 0, mZNear, mZFar); } else { // Perspective is viewing-angle, aspect-ratio, (-z, z). GLU.gluPerspective(45.0f, aspectRatio, mZNear, mZFar); } // Set the model view matrix. GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); refresh(); }
From source file:com.sriramramani.droid.inspector.ui.InspectorCanvas.java
License:Mozilla Public License
private void doPaint() { if (isDisposed() || mNode == null) { return;/*ww w . java2 s . c om*/ } setCurrent(); // Clear the color, depth and stencil buffers. GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); GL11.glLoadIdentity(); GLU.gluLookAt(0.0f, 0.0f, mCamera.z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // Transformations happen in the reverse. if (mIsOrtho) { // User's translation. GL11.glTranslatef(mOrthoTranslate.x, mOrthoTranslate.y, 0.0f); // Rotate 180 degrees. GL11.glRotatef(180.0f, 1.0f, 0.0f, 0.0f); // Center the nodes. final Rectangle bounds = getBounds(); final float scaledWidth = mNode.bounds.width * mOrthoScale; final float scaledHeight = mNode.bounds.height * mOrthoScale; GL11.glTranslatef((bounds.width - scaledWidth) / 2, 0.0f, 0.0f); // Scale based on viewport size. GL11.glTranslatef(scaledWidth / 2, -scaledHeight / 2, 0.0f); GL11.glScalef(mOrthoScale, mOrthoScale, 0.0f); GL11.glTranslatef(-scaledWidth / 2, scaledHeight / 2, 0.0f); } else { // Translate all the nodes. GL11.glTranslatef(mTranslate.x, mTranslate.y, 0.0f); // Rotate. GL11.glRotatef(mRotate.x, 1.0f, 0.0f, 0.0f); GL11.glRotatef(mRotate.y, 0.0f, 1.0f, 0.0f); // Center the nodes. GL11.glTranslatef(-mNode.bounds.width / 2, mNode.bounds.height / 2, 0.0f); } final float absX = Math.abs(mRotate.x); final float absY = Math.abs(mRotate.y); mDepth = Math.max(absX, absY) * 5 / 9.0f; drawHierarchy(mNode); if (!mIsPicking && mIsOrtho && mShowOverdraw) { for (int i = 2; i <= 5; i++) { drawOverdraw(i); } } GL11.glFlush(); if (!mIsPicking) { swapBuffers(); } }
From source file:com.swinggl.elements.GLFrame.java
License:Open Source License
/** * This method starts the both the render and update loops. The thread that this is called on will become the render loop and occupy that thread entirely. * All glfwWindowHint's must be called before this is called while all other window attributes can be altered while the loop is running including changing * the FPS and UPS./*from w w w. j a v a 2s . c o m*/ */ public void run() { if (fullscreen) { window = glfwCreateWindow(windowWidth, windowHeight, title, glfwGetPrimaryMonitor(), secondWindowHandle); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); if (!(windowWidth == vidmode.width() && windowHeight == vidmode.height())) { Debug.println("GLFWVidMode [" + windowWidth + ", " + windowHeight + "] not available, switching to GLFWVidMode [" + vidmode.width() + ", " + vidmode.height() + "]", Debug.ANSI_YELLOW); windowWidth = vidmode.width(); windowHeight = vidmode.height(); } } else window = glfwCreateWindow(windowWidth, windowHeight, title, NULL, secondWindowHandle); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); if (windowPosition == WINDOW_POSITION_CUSTOM && !fullscreen) glfwSetWindowPos(window, windowX, windowY); else if (!fullscreen) updateWindowPosition(); glfwSetKeyCallback(window, keyCallback); glfwSetCursorPosCallback(window, cursorPosCallback); glfwSetCursorEnterCallback(window, cursorEnterCallback); glfwSetMouseButtonCallback(window, mouseButtonCallback); glfwSetScrollCallback(window, scrollCallback); glfwSetWindowPosCallback(window, windowPosCallback); glfwSetWindowSizeCallback(window, windowSizeCallback); glfwSetWindowCloseCallback(window, windowCloseCallback); glfwSetWindowRefreshCallback(window, windowRefreshCallback); glfwSetWindowFocusCallback(window, windowFocusCallback); glfwSetWindowIconifyCallback(window, windowIconifyCallback); glfwSetDropCallback(window, dropCallback); if (mouseDisabled) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); else if (mouseHidden) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); else glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwMakeContextCurrent(window); glfwSwapInterval(1); GL.createCapabilities(); GLUtil.setupDebugMessageCallback(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, windowWidth, windowHeight, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glClearColor(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, backgroundColor.getAlpha() / 255f); Debug.initialize(); if (visible) glfwShowWindow(window); new Thread(new Update(), "SwingGL | update").start(); long now = System.nanoTime(); long lastTime = now; double deltaR = 0.0; long lastRender = now; running = true; while (running) { if (glfwWindowShouldClose(window) == GL_TRUE) running = false; now = System.nanoTime(); deltaR += (now - lastTime) / renderNS; lastTime = now; if (deltaR >= 1.0) { renderDelta = (now - lastRender) / 1000000000.0f; render(renderDelta); lastRender = now; deltaR--; } } if (currentGameState != null) currentGameState.dispose(); try { glfwDestroyWindow(window); keyCallback.release(); cursorPosCallback.release(); mouseButtonCallback.release(); scrollCallback.release(); } finally { glfwTerminate(); errorCallback.release(); } }