List of usage examples for org.lwjgl.opengl GL11 GL_MODELVIEW
int GL_MODELVIEW
To view the source code for org.lwjgl.opengl GL11 GL_MODELVIEW.
Click Source Link
From source file:com.samrj.devil.ui.Font.java
License:Open Source License
public void draw(String text, Vec2 pos, Vec2 align) { pos = new Vec2(pos.x, pos.y - cellHeight); align = new Vec2(align.x - 1.0f, -align.y - 1.0f).mult(0.5f); align.x *= getWidth(text);/* ww w .j av a 2s . c o m*/ align.y *= -height; pos.add(align); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glTranslatef(Math.round(pos.x), Math.round(pos.y), 0.0f); float x0 = 0f; GL11.glEnable(GL11.GL_TEXTURE_2D); tex.bind(); GL11.glBegin(GL11.GL_QUADS); for (int i = 0; i < text.length(); i++) { int charbits = text.charAt(i) - 32; int fontposx = charbits & 0xF; int fontposy = 15 - (charbits >> 4); float u0 = fontposx++ / 16f; float v0 = fontposy++ / 16f; float u1 = fontposx / 16f; float v1 = fontposy / 16f; float x1 = x0 + cellHeight; GL11.glTexCoord2f(u0, v0); GL11.glVertex2f(x0, 0f); GL11.glTexCoord2f(u0, v1); GL11.glVertex2f(x0, cellHeight); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x1, cellHeight); GL11.glTexCoord2f(u1, v0); GL11.glVertex2f(x1, 0f); x0 += getWidth(text.charAt(i)); } GL11.glEnd(); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glPopMatrix(); }
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 av a 2 s .co 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.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 2 s . 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(); } }
From source file:com.swinggl.elements.GLFrame.java
License:Open Source License
/** * Sets the size of the window from frame edge to edge. If the window is fullscreen some sizes are limited by graphical capabilities. * * @param width - The width of the window * @param height - The height of the window *//*from ww w . j ava2 s . c o m*/ public void setSize(int width, int height) { windowWidth = width; windowHeight = height; if (fullscreen) { 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(); } } if (window != 0L) { glfwSetWindowSize(window, windowWidth, windowHeight); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, windowWidth, windowHeight, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); } }
From source file:com.telinc1.rpjg.Game.java
License:Apache License
public void start() { // Start logging. Configurator.defaultConfig().writer(new ConsoleWriter()) .formatPattern("[{date:yyyy-MM-dd HH:mm:ss}] [{level}] [{class_name}] {message}").activate(); Logger.info("Creating and initializing game."); // Create the display. try {//from w w w . ja v a 2 s .c o m Display.setTitle(GameOptions.GAME_NAME); Display.setResizable(false); Display.setDisplayMode(new DisplayMode(640, 360)); Display.setVSyncEnabled(true); Display.setFullscreen(false); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(ExitCodes.INIT_DISPLAY); } finally { this.isRunning = true; Logger.info("Finished display creation."); } // Initialize OpenGL. GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0f, 0f, 0f, 0f); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); // Load all textures. TextureLoader.initialize(); // Initialize the game. this.initialize(); // Load the default map. this.loadMap("dungeon"); ModuleManager.getInstance().openModule(new ModuleMap()); // Main game loop while (this.isRunning() && !Display.isCloseRequested()) { // Clear the screen from the previous frame. GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); this.loop(); this.draw(); this.collectInput(); // Sync and update the display. Display.update(); Display.sync(GameOptions.FRAME_RATE); } // Free up all resources and exit. Logger.info("Close requested!"); TextureLoader.destroy(); Display.destroy(); Logger.info("Resources destroyed - exiting."); System.exit(ExitCodes.CLOSE_REQUESTED); }
From source file:com.w67clement.openw67render.gui.graphics.OpenGraphics.java
License:Open Source License
/** * Set OpenGL to render in flat 2D (no perspective) on top of current scene. * Preserve current projection and model views, and disable depth testing. * Ortho world size will be same as viewport size, so any ortho drawing * (drawQuad(), drawImageFullscreen(), etc.) will be scaled to fit viewport. * <p>//from w w w . j a v a 2 s.c o m * NOTE: if the viewport is the same size as the window (by default it is), * then setOrtho() will make the world coordinates exactly match the screen * pixel positions. This is convenient for mouse interaction, but be warned: * if you setViewport() to something other than fullscreen, then you need to * use getWorldCoordsAtScreen() to convert screen xy to world xy. * <p> * Once Ortho is on, glTranslate() will take pixel coords as arguments, with * the lower left corner 0,0 and the upper right corner 1024,768 (or * whatever your screen size is). !!! */ public void setOrthoOn() { int[] size = window.getSize(); int width = size[0]; int height = size[1]; // prepare projection matrix to render in 2D glMatrixMode(GL11.GL_PROJECTION); glPushMatrix(); // preserve perspective view glLoadIdentity(); // clear the perspective matrix glOrtho( // turn on 2D mode //// viewportX,viewportX+viewportW, // left, right //// viewportY,viewportY+viewportH, // bottom, top !!! 0, width, // left, right height, 0, // bottom, top -500, 500); // Zfar, Znear // clear the modelview matrix glMatrixMode(GL11.GL_MODELVIEW); glPushMatrix(); // Preserve the Modelview Matrix glLoadIdentity(); // clear the Modelview Matrix // disable depth test so further drawing will go over the current scene glDisable(GL11.GL_DEPTH_TEST); }
From source file:com.w67clement.openw67render.gui.graphics.OpenGraphics.java
License:Open Source License
/** * Turn 2D mode off. Return the projection and model views to their * preserved state that was saved when setOrthoOn() was called, and * re-enable depth testing./*from w ww . jav a 2 s. co m*/ */ public void setOrthoOff() { // restore the original positions and views glMatrixMode(GL11.GL_PROJECTION); glPopMatrix(); glMatrixMode(GL11.GL_MODELVIEW); glPopMatrix(); // turn Depth Testing back on glEnable(GL11.GL_DEPTH_TEST); }
From source file:de.minebench.zombe.liteloader.minecraft.GLHelper.java
License:Open Source License
@Override public void drawSeeThrough(float range) { float matrix[] = new float[16]; FloatBuffer buf = ByteBuffer.allocateDirect(matrix.length * 4).order(ByteOrder.nativeOrder()) .asFloatBuffer();/*from w w w. ja va 2 s . c o m*/ GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, buf); buf.get(matrix).rewind(); float w = (1.0F + matrix[10]) / matrix[14]; float dot = 1.0f - range * w; matrix[2] = 0.0f; matrix[6] = 0.0f; matrix[10] = (-2.0f / dot) + 1.0f; matrix[14] = range * (-2.0f / dot); buf.put(matrix).rewind(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadMatrix(buf); GL11.glMatrixMode(GL11.GL_MODELVIEW); }
From source file:de.mineformers.robots.client.gui.util.render.ModelDrawingHelper.java
License:LGPL
public void render(int par0, int par1, int par2) { GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glPushMatrix();// w w w. j a v a 2 s . c o m GL11.glTranslatef((float) par0, (float) par1, 50.0F); GL11.glScalef((float) (-par2), (float) par2, (float) par2); GL11.glRotatef(180F, 0, 1, 0); /*current = System.currentTimeMillis(); if(current - last >= 0) { last = current; rotation += 0.1F; }*/ rotation += 0.3F; GL11.glRotatef(rotation, 0, 1, 0); RenderHelper.bindTexture(texture); model.justRender(false); if (tile.getStackInSlot(0) != null) { Tessellator tessellator = Tessellator.instance; GL11.glPushMatrix(); GL11.glTranslatef(0, 0.35F, -0.1F); GL11.glRotatef(180, 1, 0, 0); GL11.glScalef(0.5F, 0.5F, 1F); Icon icon = ModItems.module.getIcon(tile.getStackInSlot(0), 0); float f4 = icon.getMinU(); float f5 = icon.getMaxU(); float f6 = icon.getMinV(); float f7 = icon.getMaxV(); float f9 = 0.5F; float f10 = 0.25F; float f12 = 0.0625F; float f11 = 0.021875F; ItemStack itemstack = tile.getStackInSlot(0); int j = itemstack.stackSize; byte b0 = customRenderItem.getMiniItemCount(itemstack); GL11.glTranslatef(-f9, -f10, -((f12 + f11) * (float) b0 / 2.0F)); for (int k = 0; k < b0; ++k) { // Makes items offset when in 3D, like when in 2D, looks much better. Considered a vanilla bug... GL11.glTranslatef(0f, 0f, f12 + f11); if (itemstack.getItemSpriteNumber() == 0) { RenderHelper.bindTexture(TextureMap.locationBlocksTexture); } else { RenderHelper.bindTexture(TextureMap.locationItemsTexture); } GL11.glColor4f(1, 1, 1, 1.0F); ItemRenderer.renderItemIn2D(tessellator, f5, f6, f4, f7, icon.getIconWidth(), icon.getIconHeight(), f12); if (itemstack.hasEffect(0)) { GL11.glDepthFunc(GL11.GL_EQUAL); GL11.glDisable(GL11.GL_LIGHTING); RenderManager.instance.renderEngine.bindTexture(RES_ITEM_GLINT); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); float f13 = 0.76F; GL11.glColor4f(0.5F * f13, 0.25F * f13, 0.8F * f13, 1.0F); GL11.glMatrixMode(GL11.GL_TEXTURE); GL11.glPushMatrix(); float f14 = 0.125F; GL11.glScalef(f14, f14, f14); float f15 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; GL11.glTranslatef(f15, 0.0F, 0.0F); GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12); GL11.glPopMatrix(); GL11.glPushMatrix(); GL11.glScalef(f14, f14, f14); f15 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; GL11.glTranslatef(-f15, 0.0F, 0.0F); GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDepthFunc(GL11.GL_LEQUAL); } } GL11.glPopMatrix(); } GL11.glPopMatrix(); net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); GL11.glDisable(GL11.GL_TEXTURE_2D); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); }
From source file:de.mineformers.robots.client.renderer.entity.RenderRobot.java
License:LGPL
@Override protected void renderModel(EntityLivingBase par1EntityLivingBase, float par2, float par3, float par4, float par5, float par6, float par7) { super.renderModel(par1EntityLivingBase, par2, par3, par4, par5, par6, par7); EntityRobot robot = ((EntityRobot) par1EntityLivingBase); RenderHelper.bindTexture(robot.getChipset().getHeadTexture()); ((ModelRobot) mainModel).renderEye(false); Tessellator tessellator = Tessellator.instance; GL11.glPushMatrix();/*from w w w.j av a 2 s . c o m*/ GL11.glTranslatef(0, 0.35F, -0.1F); GL11.glRotatef(180, 1, 0, 0); GL11.glScalef(0.5F, 0.5F, 1F); ItemStack itemstack = PrivateRobotHelper.createModuleStack(robot.getModule()); Icon icon = ModItems.module.getIcon(itemstack, 0); float f4 = icon.getMinU(); float f5 = icon.getMaxU(); float f6 = icon.getMinV(); float f7 = icon.getMaxV(); float f9 = 0.5F; float f10 = 0.25F; float f12 = 0.0625F; float f11 = 0.021875F; int j = itemstack.stackSize; byte b0 = customRenderItem.getMiniItemCount(itemstack); GL11.glTranslatef(-f9, -f10, -((f12 + f11) * (float) b0 / 2.0F)); for (int k = 0; k < b0; ++k) { // Makes items offset when in 3D, like when in 2D, looks much better. Considered a vanilla bug... GL11.glTranslatef(0f, 0f, f12 + f11); if (itemstack.getItemSpriteNumber() == 0) { RenderHelper.bindTexture(TextureMap.locationBlocksTexture); } else { RenderHelper.bindTexture(TextureMap.locationItemsTexture); } GL11.glColor4f(1, 1, 1, 1.0F); GL11.glRotatef(180, 0, 1, 0); GL11.glTranslatef(-1, 0, 0.05F); ItemRenderer.renderItemIn2D(tessellator, f5, f6, f4, f7, icon.getIconWidth(), icon.getIconHeight(), f12); if (itemstack.hasEffect(0)) { GL11.glDepthFunc(GL11.GL_EQUAL); GL11.glDisable(GL11.GL_LIGHTING); RenderManager.instance.renderEngine.bindTexture(RES_ITEM_GLINT); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); float f13 = 0.76F; GL11.glColor4f(0.5F * f13, 0.25F * f13, 0.8F * f13, 1.0F); GL11.glMatrixMode(GL11.GL_TEXTURE); GL11.glPushMatrix(); float f14 = 0.125F; GL11.glScalef(f14, f14, f14); float f15 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; GL11.glTranslatef(f15, 0.0F, 0.0F); GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12); GL11.glPopMatrix(); GL11.glPushMatrix(); GL11.glScalef(f14, f14, f14); f15 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; GL11.glTranslatef(-f15, 0.0F, 0.0F); GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDepthFunc(GL11.GL_LEQUAL); } } GL11.glPopMatrix(); }