List of usage examples for org.lwjgl.opengl GL11 glMatrixMode
public static native void glMatrixMode(@NativeType("GLenum") int mode);
From source file:com.mtbs3d.minecrift.VRRenderer.java
License:LGPL
public void renderGUIandWorld(float renderPartialTicks) { this.farPlaneDistance = (float) this.mc.gameSettings.ofRenderDistanceFine; if (Config.isFogFancy()) { this.farPlaneDistance *= 0.95F; }// w w w . jav a 2 s.c o m if (Config.isFogFast()) { this.farPlaneDistance *= 0.83F; } if (this.prevFarPlaneDistance != this.farPlaneDistance) { _FBOInitialised = false; this.prevFarPlaneDistance = this.farPlaneDistance; } //Ensure FBO are in place and initialized if (!setupFBOs()) return; boolean guiShowingThisFrame = false; int mouseX = 0; int mouseY = 0; ScaledResolution var15 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); int var16 = var15.getScaledWidth(); int var17 = var15.getScaledHeight(); if ((this.mc.theWorld != null && !this.mc.gameSettings.hideGUI && this.mc.thePlayer.getSleepTimer() == 0) || this.mc.currentScreen != null || this.mc.loadingScreen.isEnabled()) { //Render all UI elements into guiFBO mouseX = Mouse.getX() * var16 / this.mc.displayWidth; mouseY = var17 - Mouse.getY() * var17 / this.mc.displayHeight - 1; guiFBO.bindRenderTarget(); GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight); GL11.glClearColor(0, 0, 0, 0); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0.0D, var15.getScaledWidth_double(), var15.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(0.0F, 0.0F, -2000.0F); guiShowingThisFrame = true; } // Display loading / progress window if necessary if (this.mc.loadingScreen.isEnabled()) { this.mc.loadingScreen.vrRender(var16, var17); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); } else if (this.mc.theWorld != null && !this.mc.gameSettings.hideGUI && !this.blankGUIUntilWorldValid) { //Disable any forge gui crosshairs and helmet overlay (pumkinblur) if (Reflector.ForgeGuiIngame_renderCrosshairs.exists()) { Reflector.ForgeGuiIngame_renderCrosshairs.setValue(false); Reflector.ForgeGuiIngame_renderHelmet.setValue(false); } //Draw in game GUI this.mc.ingameGUI.renderGameOverlay(renderPartialTicks, this.mc.currentScreen != null, mouseX, mouseY); guiAchievement.updateAchievementWindow(); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); } if (this.blankGUIUntilWorldValid) { if (this.mc.theWorld != null) this.blankGUIUntilWorldValid = false; } if (this.mc.loadingScreen.isEnabled() == false && this.mc.currentScreen != null && !this.blankGUIUntilWorldValid) { try { this.mc.currentScreen.drawScreen(mouseX, mouseY, renderPartialTicks); } catch (Throwable var13) { CrashReport var11 = CrashReport.makeCrashReport(var13, "Rendering screen"); throw new ReportedException(var11); } GL11.glDisable(GL11.GL_LIGHTING); //inventory messes up fog color sometimes... This fixes GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); drawMouseQuad(mouseX, mouseY); } //Setup render target if (mc.vrSettings.useDistortion) { preDistortionFBO.bindRenderTarget(); } else if (this.mc.vrSettings.useSupersample) { postDistortionFBO.bindRenderTarget(); eyeRenderParams._renderScale = 1.0f; } else { unbindFBORenderTarget(); eyeRenderParams._renderScale = 1.0f; } GL11.glClearColor(0, 0, 0, 1); GL11.glEnable(GL11.GL_SCISSOR_TEST); if (this.mc.theWorld != null) { //If we're in-game, render in-game stuff this.mc.mcProfiler.startSection("level"); if (this.mc.renderViewEntity == null) { this.mc.renderViewEntity = this.mc.thePlayer; } EntityLivingBase renderViewEntity = this.mc.renderViewEntity; this.mc.mcProfiler.endStartSection("center"); //Used by fog comparison, 3rd person camera/block collision detection renderOriginX = renderViewEntity.lastTickPosX + (renderViewEntity.posX - renderViewEntity.lastTickPosX) * (double) renderPartialTicks; renderOriginY = renderViewEntity.lastTickPosY + (renderViewEntity.posY - renderViewEntity.lastTickPosY) * (double) renderPartialTicks; renderOriginZ = renderViewEntity.lastTickPosZ + (renderViewEntity.posZ - renderViewEntity.lastTickPosZ) * (double) renderPartialTicks; if (this.mc.currentScreen == null) { this.mc.mcProfiler.endStartSection("pick"); getPointedBlock(renderPartialTicks); } // Update sound engine setSoundListenerOrientation(); } //Update gui Yaw if (guiShowingThisFrame && !guiShowingLastFrame) { guiHeadYaw = this.cameraYaw - this.mc.lookaimController.getBodyYawDegrees(); } guiShowingLastFrame = guiShowingThisFrame; //Now, actually render world for (int renderSceneNumber = 0; renderSceneNumber < 2; ++renderSceneNumber) { setupEyeViewport(renderSceneNumber); this.mc.mcProfiler.endStartSection("camera"); //transform camera with pitch,yaw,roll + neck model + game effects setupCameraTransform(renderPartialTicks, renderSceneNumber); if (this.mc.theWorld != null) { GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); this.renderWorld(renderPartialTicks, 0L, renderSceneNumber); this.disableLightmap(renderPartialTicks); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPopMatrix(); } else { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the framebuffer to black GL11.glDisable(GL11.GL_BLEND); } if (guiShowingThisFrame) { GL11.glPushMatrix(); GL11.glEnable(GL11.GL_TEXTURE_2D); guiFBO.bindTexture(); // Prevent black border at top / bottom of GUI GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); if (this.mc.theWorld != null && this.mc.vrSettings.hudLockToHead) { GL11.glLoadIdentity(); if (renderSceneNumber == 0) GL11.glMultMatrix(eyeRenderParams.gl_getLeftViewportTransform()); else GL11.glMultMatrix(eyeRenderParams.gl_getRightViewportTransform()); GL11.glRotatef(180f - this.mc.vrSettings.hudYawOffset, 0f, 1f, 0f); GL11.glRotatef(-this.mc.vrSettings.hudPitchOffset, 1f, 0f, 0f); // GL11.glRotatef(cameraRoll, 0f, 0f, 1f); GL11.glTranslatef(0.0f, 0.0f, this.mc.vrSettings.hudDistance - this.mc.vrSettings.eyeProtrusion); GL11.glRotatef(180f, 0f, 1f, 0f);//Not sure why this is necessary... normals/backface culling maybe? } else { float guiYaw = 0f; if (this.mc.theWorld != null) { if (this.mc.vrSettings.lookMoveDecoupled) guiYaw = this.mc.lookaimController.getBodyYawDegrees(); else guiYaw = guiHeadYaw + this.mc.lookaimController.getBodyYawDegrees(); guiYaw -= this.mc.vrSettings.hudYawOffset; } else guiYaw = guiHeadYaw + this.mc.lookaimController.getBodyYawDegrees(); GL11.glRotatef(-guiYaw, 0f, 1f, 0f); float guiPitch = 0f; if (this.mc.theWorld != null) guiPitch = -this.mc.vrSettings.hudPitchOffset; // if( this.mc.vrSettings.allowMousePitchInput) // guiPitch += this.mc.lookaimController.getBodyPitchDegrees(); GL11.glRotatef(guiPitch, 1f, 0f, 0f); GL11.glTranslatef(0.0f, 0.0f, this.mc.vrSettings.hudDistance); GL11.glRotatef(180f, 0f, 1f, 0f);//Not sure why this is necessary... normals/backface culling maybe? } GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); if (this.mc.theWorld != null) GL11.glColor4f(1, 1, 1, this.mc.vrSettings.hudOpacity); else GL11.glColor4f(1, 1, 1, 1); if (!this.mc.vrSettings.hudOcclusion) GL11.glDisable(GL11.GL_DEPTH_TEST); drawQuad2(this.mc.displayWidth, this.mc.displayHeight, this.mc.vrSettings.hudScale * this.mc.vrSettings.hudDistance); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glPopMatrix(); unbindTexture(); //mc.checkGLError("GUI"); } if (calibrationHelper != null) { float x = lookX * mc.vrSettings.hudDistance; float y = lookY * mc.vrSettings.hudDistance; float z = lookZ * mc.vrSettings.hudDistance; GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); GL11.glRotatef(-this.cameraYaw, 0.0F, 1.0F, 0.0F); GL11.glRotatef(this.cameraPitch, 1.0F, 0.0F, 0.0F); GL11.glRotatef(this.cameraRoll, 0.0F, 0.0F, 1.0F); float textScale = (float) Math.sqrt((x * x + y * y + z * z)); GL11.glScalef(-INITIAL_CALIBRATION_TEXT_SCALE * textScale, -INITIAL_CALIBRATION_TEXT_SCALE * textScale, -INITIAL_CALIBRATION_TEXT_SCALE * textScale); String calibrating = "Calibrating " + calibrationHelper.currentPlugin.getName() + "..."; mc.fontRenderer.drawStringWithShadow(calibrating, -mc.fontRenderer.getStringWidth(calibrating) / 2, -8, /*white*/16777215); String calibrationStep = calibrationHelper.calibrationStep; // mc.fontRenderer.drawStringWithShadow(calibrationStep, -mc.fontRenderer.getStringWidth(calibrationStep)/2, 8, /*white*/16777215); int column = 8; ArrayList<String> wrapped = new ArrayList<String>(); Utils.wordWrap(calibrationStep, CALIBRATION_TEXT_WORDWRAP_LEN, wrapped); for (String line : wrapped) { mc.fontRenderer.drawStringWithShadow(line, -mc.fontRenderer.getStringWidth(line) / 2, column, /*white*/16777215); column += 16; } GL11.glPopMatrix(); GL11.glEnable(GL11.GL_DEPTH_TEST); } } GL11.glDisable(GL11.GL_SCISSOR_TEST); doDistortionAndSuperSample(); checkLatencyTester(); // Finish frame GL11.glFinish(); // Get end frame timings endFrameTimeNanos = startVSyncPeriodNanos = System.nanoTime(); long frameTime = endFrameTimeNanos - startFrameRenderNanos; addRenderFrameTimeNanos(frameTime); mc.checkGLError("After render world and GUI"); }
From source file:com.mtbs3d.minecrift.VRRenderer.java
License:LGPL
private void doDistortionAndSuperSample() { int FBWidth = this.mc.displayFBWidth; int FBHeight = this.mc.displayFBHeight; if (this.mc.vrSettings.useDistortion || this.mc.vrSettings.useSupersample || this.mc.vrSettings.useFXAA) { // Setup ortho projection GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity();/* w w w . j a va 2 s.c om*/ GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -0.7f); } if (this.mc.vrSettings.useSupersample) { FBWidth = (int) ceil(this.mc.displayFBWidth * this.mc.vrSettings.superSampleScaleFactor); FBHeight = (int) ceil(this.mc.displayFBHeight * this.mc.vrSettings.superSampleScaleFactor); } if (mc.vrSettings.useDistortion) { //mc.checkGLError("Before distortion"); preDistortionFBO.bindTexture(); if (this.mc.vrSettings.useFXAA) { //chain into the FXAA FBO fxaaFBO.bindRenderTarget(); } else if (this.mc.vrSettings.useSupersample) { //chain into the superSample FBO postDistortionFBO.bindRenderTarget(); } else { unbindFBORenderTarget(); } GL11.glClearColor(1.0f, 1.0f, 1.0f, 0.5f); GL11.glClearDepth(1.0D); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the framebuffer to black // Render onto the entire screen framebuffer GL11.glViewport(0, 0, FBWidth, FBHeight); // Set the distortion shader as in use ARBShaderObjects.glUseProgramObjectARB(_Distortion_shaderProgramId); // Set up the fragment shader uniforms ARBShaderObjects.glUniform1iARB(_DistortionShader_RenderTextureUniform, 0); if (this.mc.vrSettings.useDistortionTextureLookupOptimisation) { distortParams.bindTexture_Unit1(); ARBShaderObjects.glUniform1iARB(_DistortionShader_DistortionMapUniform, 1); } ARBShaderObjects.glUniform1iARB(_DistortionShader_half_screenWidthUniform, distortParams.half_screenWidth); ARBShaderObjects.glUniform2fARB(_DistortionShader_LeftLensCenterUniform, distortParams.leftLensCenterX, distortParams.leftLensCenterY); ARBShaderObjects.glUniform2fARB(_DistortionShader_RightLensCenterUniform, distortParams.rightLensCenterX, distortParams.rightLensCenterY); ARBShaderObjects.glUniform2fARB(_DistortionShader_LeftScreenCenterUniform, distortParams.leftScreenCenterX, distortParams.leftScreenCenterY); ARBShaderObjects.glUniform2fARB(_DistortionShader_RightScreenCenterUniform, distortParams.rightScreenCenterX, distortParams.rightScreenCenterY); ARBShaderObjects.glUniform2fARB(_DistortionShader_ScaleUniform, distortParams.scaleX, distortParams.scaleY); ARBShaderObjects.glUniform2fARB(_DistortionShader_ScaleInUniform, distortParams.scaleInX, distortParams.scaleInY); ARBShaderObjects.glUniform4fARB(_DistortionShader_HmdWarpParamUniform, distortParams.DistortionK[0], distortParams.DistortionK[1], distortParams.DistortionK[2], distortParams.DistortionK[3]); ARBShaderObjects.glUniform4fARB(_DistortionShader_ChromAbParamUniform, distortParams.ChromaticAb[0], distortParams.ChromaticAb[1], distortParams.ChromaticAb[2], distortParams.ChromaticAb[3]); drawQuad(); // Stop shader use ARBShaderObjects.glUseProgramObjectARB(0); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); //mc.checkGLError("After distortion"); } if (this.mc.vrSettings.useFXAA) { fxaaFBO.bindTexture(); if (this.mc.vrSettings.useSupersample) { //chain into the superSample FBO postDistortionFBO.bindRenderTarget(); } else { unbindFBORenderTarget(); } GL11.glClearColor(1.0f, 1.0f, 1.0f, 0.5f); GL11.glClearDepth(1.0D); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the framebuffer to black // Render onto the entire screen framebuffer GL11.glViewport(0, 0, FBWidth, FBHeight); // Set the distortion shader as in use ARBShaderObjects.glUseProgramObjectARB(_FXAA_shaderProgramId); // Set up the fragment shader uniforms ARBShaderObjects.glUniform1iARB(_FXAA_RenderTextureUniform, 0); ARBShaderObjects.glUniform2fARB(_FXAA_RenderedTextureSizeUniform, (float) FBWidth, (float) FBHeight); drawQuad(); // Stop shader use ARBShaderObjects.glUseProgramObjectARB(0); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); //ShaderHelper.checkGLError("After fxaa"); } if (this.mc.vrSettings.useSupersample) { // Now switch to 1st pass target framebuffer postSuperSampleFBO.bindRenderTarget(); // Bind the FBO postDistortionFBO.bindTexture(); GL11.glClearColor(0.0f, 0.0f, 1.0f, 0.5f); GL11.glClearDepth(1.0D); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the framebuffer to black // Render onto the entire screen framebuffer GL11.glViewport(0, 0, this.mc.displayFBWidth, FBHeight); // Set the downsampling shader as in use ARBShaderObjects.glUseProgramObjectARB(_Lanczos_shaderProgramId); // Set up the fragment shader uniforms ARBShaderObjects.glUniform1fARB(_LanczosShader_texelWidthOffsetUniform, 1.0f / (3.0f * (float) this.mc.displayFBWidth)); ARBShaderObjects.glUniform1fARB(_LanczosShader_texelHeightOffsetUniform, 0.0f); ARBShaderObjects.glUniform1iARB(_LanczosShader_inputImageTextureUniform, 0); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); // Pass 1 drawQuad(); // mc.checkGLError("After Lanczos Pass1"); // Pass 2 // Now switch to 2nd pass screen framebuffer unbindFBORenderTarget(); postSuperSampleFBO.bindTexture(); GL11.glViewport(0, 0, this.mc.displayFBWidth, this.mc.displayFBHeight); GL11.glClearColor(0.0f, 0.0f, 1.0f, 0.5f); GL11.glClearDepth(1.0D); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Bind the texture GL13.glActiveTexture(GL13.GL_TEXTURE0); // Set up the fragment shader uniforms for pass 2 ARBShaderObjects.glUniform1fARB(_LanczosShader_texelWidthOffsetUniform, 0.0f); ARBShaderObjects.glUniform1fARB(_LanczosShader_texelHeightOffsetUniform, 1.0f / (3.0f * (float) this.mc.displayFBHeight)); ARBShaderObjects.glUniform1iARB(_LanczosShader_inputImageTextureUniform, 0); drawQuad(); // Stop shader use ARBShaderObjects.glUseProgramObjectARB(0); // mc.checkGLError("After Lanczos Pass2"); } }
From source file:com.mtbs3d.minecrift.VRRenderer.java
License:LGPL
public void drawLatencyTesterColoredQuad(float r, float g, float b, float a) { GL11.glDisable(GL11.GL_TEXTURE_2D);/*from w w w . ja v a 2s .c om*/ GL11.glEnable(GL11.GL_BLEND); // Setup ortho projection GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -0.7f); // Cover the appropriate areas of the screen with the colored quad GL11.glBegin(GL11.GL_QUADS); GL11.glColor4f(r, g, b, a); GL11.glVertex3f(-0.6f, -0.6f, 0.0f); // Bottom Left Of The Texture and Quad GL11.glVertex3f(0.6f, -0.6f, 0.0f); // Bottom Right Of The Texture and Quad GL11.glVertex3f(0.6f, 0.6f, 0.0f); // Top Right Of The Texture and Quad GL11.glVertex3f(-0.6f, 0.6f, 0.0f); // Top Left Of The Texture and Quad GL11.glEnd(); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_TEXTURE_2D); }
From source file:com.mtbs3d.minecrift.VRRenderer.java
License:LGPL
/** * Render player hand//from w w w . ja v a 2 s . c o m */ private void renderHand(float par1, int renderSceneNumber) { if (this.debugViewDirection <= 0) { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glLoadIdentity(); if (renderSceneNumber == 0) { // Left eye FloatBuffer leftProj = eyeRenderParams.gl_getLeftProjectionMatrix(); GL11.glLoadMatrix(leftProj); //mc.checkGLError("Set left projection"); } else { // Right eye FloatBuffer rightProj = eyeRenderParams.gl_getRightProjectionMatrix(); GL11.glLoadMatrix(rightProj); //mc.checkGLError("Set right projection"); } float var3 = 0.07F; if (this.mc.gameSettings.anaglyph) { GL11.glTranslatef((float) (-(renderSceneNumber * 2 - 1)) * var3, 0.0F, 0.0F); } if (this.cameraZoom != 1.0D) { GL11.glTranslatef((float) this.cameraYaw, (float) (-this.cameraPitch), 0.0F); GL11.glScaled(this.cameraZoom, this.cameraZoom, 1.0D); } if (this.mc.playerController.enableEverythingIsScrewedUpMode()) { float var4 = 0.6666667F; GL11.glScalef(1.0F, var4, 1.0F); } GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); // IPD transformation if (renderSceneNumber == 0) { // Left eye FloatBuffer leftEyeTransform = eyeRenderParams.gl_getLeftViewportTransform(); GL11.glMultMatrix(leftEyeTransform); } else { // Right eye FloatBuffer rightEyeTransform = eyeRenderParams.gl_getRightViewportTransform(); GL11.glMultMatrix(rightEyeTransform); } if (this.mc.gameSettings.anaglyph) { GL11.glTranslatef((float) (renderSceneNumber * 2 - 1) * 0.1F, 0.0F, 0.0F); } GL11.glPushMatrix(); this.hurtCameraEffect(par1); if (this.mc.gameSettings.viewBobbing) { this.setupViewBobbing(par1); } if (this.mc.gameSettings.thirdPersonView == 0 && !this.mc.renderViewEntity.isPlayerSleeping() && !this.mc.playerController.enableEverythingIsScrewedUpMode()) { this.enableLightmap((double) par1); this.itemRenderer.renderItemInFirstPerson(par1); this.disableLightmap((double) par1); } GL11.glPopMatrix(); if (this.mc.gameSettings.thirdPersonView == 0 && !this.mc.renderViewEntity.isPlayerSleeping()) { this.itemRenderer.renderOverlays(par1); this.hurtCameraEffect(par1); } if (this.mc.gameSettings.viewBobbing) { this.setupViewBobbing(par1); } GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); } }
From source file:com.n8lm.zener.nifty.NiftyGUISystem.java
License:Open Source License
@Override protected void processSystem() { glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight()); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity();/*w w w . ja v a 2s . co m*/ GL11.glOrtho(0, game.getContainer().getWidth(), game.getContainer().getHeight(), 0, -9999, 9999); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); glPushAttrib(GL_ENABLE_BIT); GL11.glDisable(GL11.GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glAlphaFunc(GL11.GL_NOTEQUAL, 0); GL11.glDisable(GL11.GL_LIGHTING); // Back to GL Texture 0 Unit glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); //glBindTexture(); nifty.update(); nifty.render(false); glPopAttrib(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); }
From source file:com.ogrekill.Engine.java
public static void initDisplay() { try {/* www .j a va 2 s .c om*/ Display.setDisplayMode(new DisplayMode(800, 600)); Display.create(); } catch (LWJGLException e) { System.exit(0); } //init OpenGL GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, 800, 0, 600, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); while (!Display.isCloseRequested()) { Display.update(); } Display.destroy(); }
From source file:com.owens.oobjloader.Main.java
License:BSD License
/** * @throws Exception if init fails//from www .jav a 2s . c om */ private static void init(boolean fullscreen) throws Exception { // Create a fullscreen window with 1:1 orthographic 2D projection (default) Display.setTitle(WINDOW_TITLE); Display.setFullscreen(fullscreen); // Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work) Display.setVSyncEnabled(true); // Create default display of 640x480 Display.create(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float fAspect = (float) Display.getDisplayMode().getWidth() / (float) Display.getDisplayMode().getHeight(); GLU.gluPerspective(45.0f, fAspect, 1.0f, 400.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glViewport(0, 0, Display.getDisplayMode().getWidth() - 100, Display.getDisplayMode().getHeight() - 100); }
From source file:com.owens.oobjloader.Main.java
License:BSD License
/** * Runs the program (the "main loop")/*from w ww.j a v a 2s. co m*/ */ 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.pahimar.ee3.core.handlers.TransmutationTargetOverlayHandler.java
License:LGPL
private static void renderStoneHUD(Minecraft minecraft, EntityPlayer player, ItemStack stack, float partialTicks) { float overlayScale = ConfigurationSettings.TARGET_BLOCK_OVERLAY_SCALE; float blockScale = overlayScale / 2; float overlayOpacity = ConfigurationSettings.TARGET_BLOCK_OVERLAY_OPACITY; GL11.glPushMatrix();/* www .j a v a2 s. c o m*/ ScaledResolution sr = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight); GL11.glClear(256); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0.0D, sr.getScaledWidth_double(), sr.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(0.0F, 0.0F, -2000.0F); GL11.glPushMatrix(); RenderHelper.enableGUIStandardItemLighting(); GL11.glDisable(GL11.GL_LIGHTING); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glEnable(GL11.GL_LIGHTING); int hudOverlayX = 0; int hudOverlayY = 0; int hudBlockX = 0; int hudBlockY = 0; switch (ConfigurationSettings.TARGET_BLOCK_OVERLAY_POSITION) { case 0: { hudOverlayX = 0; hudBlockX = (int) (16 * overlayScale / 2 - 8); hudOverlayY = 0; hudBlockY = (int) (16 * overlayScale / 2 - 8); break; } case 1: { hudOverlayX = (int) (sr.getScaledWidth() - 16 * overlayScale); hudBlockX = (int) (sr.getScaledWidth() - 16 * overlayScale / 2 - 8); hudOverlayY = 0; hudBlockY = (int) (16 * overlayScale / 2 - 8); break; } case 2: { hudOverlayX = 0; hudBlockX = (int) (16 * overlayScale / 2 - 8); hudOverlayY = (int) (sr.getScaledHeight() - 16 * overlayScale); hudBlockY = (int) (sr.getScaledHeight() - 16 * overlayScale / 2 - 8); break; } case 3: { hudOverlayX = (int) (sr.getScaledWidth() - 16 * overlayScale); hudBlockX = (int) (sr.getScaledWidth() - 16 * overlayScale / 2 - 8); hudOverlayY = (int) (sr.getScaledHeight() - 16 * overlayScale); hudBlockY = (int) (sr.getScaledHeight() - 16 * overlayScale / 2 - 8); break; } default: { break; } } RenderUtils.renderItemIntoGUI(minecraft.fontRenderer, minecraft.renderEngine, stack, hudOverlayX, hudOverlayY, overlayOpacity, overlayScale); if (TransmutationHelper.targetBlockStack != null && TransmutationHelper.targetBlockStack.getItem() instanceof ItemBlock) { RenderUtils.renderRotatingBlockIntoGUI(minecraft.fontRenderer, minecraft.renderEngine, TransmutationHelper.targetBlockStack, hudBlockX, hudBlockY, -90, blockScale); } GL11.glDisable(GL11.GL_LIGHTING); GL11.glPopMatrix(); GL11.glPopMatrix(); }
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 www. ja v a 2s .c om*/ 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(); } }