/** * ************************************************************************************************************************************************************************************************* * Initialization stuff comes in here... * ************************************************************************************************************************************************************************************************ */ private void init() { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setVSyncEnabled(true); Display.setTitle("MS3D Loader [G36C]"); Display.create(); Keyboard.create(); } catch (LWJGLException e) { Sys.alert("Error", "Initialization failed!\n\n" + e.getMessage()); System.exit(0); } /* OpenGL */ int width = Display.getDisplayMode().getWidth(); int height = Display.getDisplayMode().getHeight(); GL11.glViewport(0, 0, width, height); // Reset The Current Viewport GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix GL11.glLoadIdentity(); // Reset The Projection Matrix GLU.gluPerspective( 45.0f, ((float) width / (float) height), 0.1f, 1000.0f); // Calculate The Aspect Ratio Of The Window GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix GL11.glLoadIdentity(); // Reset The Modelview Matrix GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Background color GL11.glClearDepth(1.0f); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); // Load model // g36c = new // MS3DModel(resourceLoader.loadResourceAsStream("models/gsg9.ms3d"),this.getClass().getResource("./data/textures").getPath()); g36c = new MS3DModel( resourceLoader.loadResourceAsStream("models/assassin.ms3d"), this.getClass().getResource("./data/textures").getPath()); // tdsLoader=new TDSLoader(); // try { // tdsLoader.load(resourceLoader.loadResourceAsStream("models/face.3ds")); // System.out.println(tdsLoader.getObjectSize()); // } catch (IOException e) { // e.printStackTrace(); // } // Load font font = new Font(resourceLoader.loadResourceAsStream("textures/font.bmp"), 12, width, height); // Init timer timer = new Timer(); }
public static void updateRenderInfo(EntityPlayer par0EntityPlayer, boolean par1) { GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview); GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection); // Spout start modelMatrix = modelview.duplicate(); projectionMatrix = projection.duplicate(); // Spout end GL11.glGetInteger(GL11.GL_VIEWPORT, viewport); float var2 = (float) ((viewport.get(0) + viewport.get(2)) / 2); float var3 = (float) ((viewport.get(1) + viewport.get(3)) / 2); GLU.gluUnProject(var2, var3, 0.0F, modelview, projection, viewport, objectCoords); objectX = objectCoords.get(0); objectY = objectCoords.get(1); objectZ = objectCoords.get(2); int var4 = par1 ? 1 : 0; float var5 = par0EntityPlayer.rotationPitch; float var6 = par0EntityPlayer.rotationYaw; rotationX = MathHelper.cos(var6 * (float) Math.PI / 180.0F) * (float) (1 - var4 * 2); rotationZ = MathHelper.sin(var6 * (float) Math.PI / 180.0F) * (float) (1 - var4 * 2); rotationYZ = -rotationZ * MathHelper.sin(var5 * (float) Math.PI / 180.0F) * (float) (1 - var4 * 2); rotationXY = rotationX * MathHelper.sin(var5 * (float) Math.PI / 180.0F) * (float) (1 - var4 * 2); rotationXZ = MathHelper.cos(var5 * (float) Math.PI / 180.0F); }
public void render() { lock.lock(); quads = 0; draw_calls = 0; batch_draw_calls = 0; GL11.glLoadIdentity(); GLU.gluLookAt( camera.pos.x, camera.pos.y, camera.pos.z, camera.pos.x + camera.look.x, camera.pos.y + camera.look.y, camera.pos.z + camera.look.z, camera.up.x, camera.up.y, camera.up.z); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); for (ChunkNode.Batch batch : batches) render_batch(batch); GL11.glFlush(); lock.unlock(); }
private void setupShaders() { int errorCheckValue = GL11.glGetError(); // Load the vertex shader vsId = this.loadShader("vertex.glsl", GL20.GL_VERTEX_SHADER); // Load the fragment shader fsId = this.loadShader("fragment.glsl", GL20.GL_FRAGMENT_SHADER); // Create a new shader program that links both shaders pId = GL20.glCreateProgram(); GL20.glAttachShader(pId, vsId); GL20.glAttachShader(pId, fsId); // Position information will be attribute 0 GL20.glBindAttribLocation(pId, 0, "in_Position"); // Color information will be attribute 1 GL20.glBindAttribLocation(pId, 1, "in_Color"); GL20.glLinkProgram(pId); GL20.glValidateProgram(pId); errorCheckValue = GL11.glGetError(); if (errorCheckValue != GL11.GL_NO_ERROR) { System.out.println( "ERROR - Could not create the shaders:" + GLU.gluErrorString(errorCheckValue)); System.exit(-1); } }
/** Regenerates any dirty mimaps. */ public void regenerateMipmaps() { if (mipmapDirty) { ByteBuffer data1 = BufferUtils.createByteBuffer(size.getWidth() * size.getHeight() * format.bytes); ByteBuffer data = data1; GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // read the texture out GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, format.glFormat, GL11.GL_UNSIGNED_BYTE, data); data.rewind(); // regenerate the mipmaps GLU.gluBuild2DMipmaps( GL11.GL_TEXTURE_2D, format.glInternalFormat, size.getWidth(), size.getHeight(), format.glFormat, GL11.GL_UNSIGNED_BYTE, data); mipmapDirty = false; } }
@Override public boolean gluUnProject( float winX, float winY, float winZ, float[] model, int modelOffset, float[] project, int projectOffset, int[] view, int viewOffset, float[] obj, int objOffset) { modelb.clear(); modelb.put(model, modelOffset, 16); projectb.clear(); projectb.put(project, projectOffset, 16); viewb.clear(); viewb.put(view, viewOffset, 4); winb.clear(); boolean result = org.lwjgl.util.glu.GLU.gluUnProject(winX, winY, winZ, modelb, projectb, viewb, winb); obj[objOffset] = winb.get(0); obj[objOffset + 1] = winb.get(1); obj[objOffset + 2] = winb.get(2); return result; }
/** * Replaces the projection matrix by the one generated by the camera. The matrix mode will be * returned it its previous value. to GL_MODELVIEW. */ public void applyPerspectiveMatrix() { int previousMatrixMode = glGetInteger(GL_MATRIX_MODE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLU.gluPerspective(fov, aspectRatio, zNear, zFar); glMatrixMode(previousMatrixMode); }
/** Enters the Main-Loop */ private void beginLoop() { this.isRunning = true; this.timing.init(); while (this.isRunning) { int delta = this.timing.getDelta(); this.handleDisplayResize(); if (Display.isCloseRequested()) this.isRunning = false; // Mouse updates this.profiler.start("Mouse updates"); this.mouseX = Mouse.getX(); this.mouseY = this.height - Mouse.getY(); if (!this.isGamePaused) { this.input.mousePos(this.mouseX, this.mouseY); if (Mouse.isButtonDown(0) && !this.lastButtonState) this.input.mouseClick(this.mouseX, this.mouseY); this.lastButtonState = Mouse.isButtonDown(0); } // Scrolling if (!this.isGamePaused) { int scroll = Mouse.getDWheel(); if (scroll > 0) this.camera.zoom(-1); else if (scroll < 0) this.camera.zoom(1); } // Keyboard updates this.profiler.endStart("Keyboard updates"); this.keyboardListener.update(); // Audio this.profiler.endStart("Audio updates"); this.soundEngine.update(delta); // Rendering this.profiler.endStart("Render game"); this.camera.update(delta); this.renderer.render(this.camera, this.logic.getGameState(), delta); this.profiler.endStart("Render GUI"); this.guiRenderer.render(this.width, this.height, this.mouseX, this.mouseY); this.profiler.end(); Display.update(); Display.sync(60); int error = glGetError(); if (error != GL_NO_ERROR) System.out.println("GLError " + error + ": " + GLU.gluErrorString(error)); this.timing.updateFPS(); } this.soundEngine.dispose(); Settings.saveSettings(this.settings); if (Display.isCreated()) Display.destroy(); }
public static void checkGlError(String var0) { int var1 = GL11.glGetError(); if (var1 != 0) { String var2 = GLU.gluErrorString(var1); dbg("OpenGlError: " + var1 + " (" + var2 + "), at: " + var0); } }
void setup_camera(float fov, float ratio, float view_distance) { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective(fov, ratio, 0.01f, view_distance); GL11.glMatrixMode(GL11.GL_MODELVIEW); camera.set_attribs(fov, ratio, 0.01f, view_distance); }
public static Vec3 unproject(float winX, float winY, float winZ) { GLU.gluUnProject(winX, winY, winZ, modelview, projection, viewport, objectCoords); float objectX = objectCoords.get(0); float objectY = objectCoords.get(1); float objectZ = objectCoords.get(2); return Vec3.createVectorHelper(objectX, objectY, objectZ); }
private void checkGLError(String s) { int i = GL11.glGetError(); if (i != 0) { String s1 = GLU.gluErrorString(i); System.out.println("########## GL ERROR ##########"); System.out.println((new StringBuilder()).append("@ ").append(s).toString()); System.out.println((new StringBuilder()).append(i).append(": ").append(s1).toString()); } }
private void initGL() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // sets background to grey glClearDepth(1.0f); // clear depth buffer glEnable(GL_DEPTH_TEST); // Enables depth testing glDepthFunc(GL_LEQUAL); // sets the type of test to use for depth testing glMatrixMode(GL_PROJECTION); // sets the matrix mode to project // GLU.gluOrtho2D(-10, 10, -10, 10); // GLU.gluOrtho2D(0 - COORD_WIDTH / 2, 0 + COORD_WIDTH / 2, 0 - COORD_HEIGHT / 2, 0 + // COORD_HEIGHT / 2); float fovy = 90.0f; float aspect = DISPLAY_MODE.getWidth() / (float) DISPLAY_MODE.getHeight(); float zNear = 0.1f; float zFar = 20000.0f; GLU.gluPerspective(fovy, aspect, zNear, zFar); glViewport(0, 0, DISPLAY_MODE.getWidth(), DISPLAY_MODE.getHeight()); // GLU.gluOrtho2D(-10, 10, -10, 10); // GLU.gluOrtho2D(-1, 1, -1, 1); glOrtho( 0 - COORD_WIDTH / 2, 0 + COORD_WIDTH / 2, 0 - COORD_HEIGHT / 2, 0 + COORD_HEIGHT / 2, zNear, zFar); System.out.println(COORD_WIDTH + ", " + COORD_HEIGHT); glMatrixMode(GL_MODELVIEW); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // ----------- Variables & method calls added for Lighting Test -----------// initLightArrays(); glShadeModel(GL_SMOOTH); glMaterial(GL_FRONT, GL_SPECULAR, matSpecular); // sets specular material color glMaterialf(GL_FRONT, GL_SHININESS, 50.0f); // sets shininess glLight(GL_LIGHT0, GL_POSITION, lightPosition); // sets light position glLight(GL_LIGHT0, GL_SPECULAR, whiteLight); // sets specular light to white glLight(GL_LIGHT0, GL_DIFFUSE, whiteLight); // sets diffuse light to white glLightModel(GL_LIGHT_MODEL_AMBIENT, lModelAmbient); // global ambient light glEnable(GL_LIGHTING); // enables lighting glEnable(GL_LIGHT0); // enables light0 glEnable(GL_COLOR_MATERIAL); // enables opengl to use glColor3f to define material color glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // tell opengl glColor3f effects the ambient and diffuse properties // of material // ----------- END: Variables & method calls added for Lighting Test -----------// }
private static void doPicking() { IntBuffer buffer = ByteBuffer.allocateDirect(nextName).asIntBuffer(); GL11.glSelectBuffer(buffer); GL11.glRenderMode(GL11.GL_SELECT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glLoadIdentity(); GLU.gluPickMatrix(Mouse.getX(), Mouse.getY(), 4, 4, buffer); GL11.glRenderMode(GL11.GL_RENDER); }
private FancyDial(TextureAtlasSprite icon, PropertiesFile properties) { this.icon = icon; this.properties = properties; name = IconAPI.getIconName(icon); x0 = IconAPI.getIconX0(icon); y0 = IconAPI.getIconY0(icon); width = IconAPI.getIconWidth(icon); height = IconAPI.getIconHeight(icon); scratchBuffer = ByteBuffer.allocateDirect(4 * width * height); int itemsTexture = TexturePackAPI.getTextureIfLoaded(TexturePackAPI.ITEMS_PNG); if (itemsTexture < 0) { logger.severe("could not get items texture"); return; } itemsFBO = new FBO(itemsTexture, x0, y0, width, height); if (useScratchTexture) { logger.fine("rendering %s to %dx%d scratch texture", name, width, height); for (int i = 0; i < scratchFBO.length; i++) { scratchFBO[i] = new FBO(width, height); } } else { logger.fine("rendering %s directly to atlas", name); } boolean debug = false; for (int i = 0; ; i++) { Layer layer = newLayer(properties, "." + i); if (layer == null) { if (i > 0) { break; } continue; } layers.add(layer); debug |= layer.debug; logger.fine(" new %s", layer); } keyboard = new InputHandler(name, debug); if (layers.size() < 2) { logger.error("custom %s needs at least two layers defined", name); return; } outputFrames = properties.getInt("outputFrames", 0); int glError = GL11.glGetError(); if (glError != 0) { logger.severe("%s during %s setup", GLU.gluErrorString(glError), name); return; } ok = true; }
public static void set() { GL11.glViewport(0, 0, HouseCalc.programFrame.getWidth(), HouseCalc.programFrame.getHeight()); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float width = HouseCalc.programFrame.getWidth(); float height = HouseCalc.programFrame.getHeight(); GLU.gluPerspective(70, width / height, 0.1f, 600.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GLU.gluLookAt( (float) posx, (float) posy, (float) posz, (float) posx + dirx, (float) posy + diry, (float) posz + dirz, 0, 1, 0); MatrixTools.multMatrix(matrix); }
@SubscribeEvent @SideOnly(Side.CLIENT) public void renderLast(RenderWorldLastEvent evt) { // TODO: while the urbanist is deactivated, this code can be dormant. // it happens to be very expensive at run time, so we need some way // to operate it only when relevant (e.g. in the cycle following a // click request). if (NONRELEASED_BLOCKS) { return; } /** * Note (SpaceToad): Why on earth this thing eventually worked out is a mystery to me. In * particular, all the examples I got computed y in a different way. Anyone with further OpenGL * understanding would be welcome to explain. * * <p>Anyway, the purpose of this code is to store the block position pointed by the mouse at * each frame, relative to the entity that has the camera. * * <p>It got heavily inspire from the two following sources: * http://nehe.gamedev.net/article/using_gluunproject/16013/ #ActiveRenderInfo.updateRenderInfo. * * <p>See EntityUrbanist#rayTraceMouse for a usage example. */ if (modelviewF == null) { modelviewF = GLAllocation.createDirectFloatBuffer(16); projectionF = GLAllocation.createDirectFloatBuffer(16); viewport = GLAllocation.createDirectIntBuffer(16); } GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelviewF); GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionF); GL11.glGetInteger(GL11.GL_VIEWPORT, viewport); float f = (viewport.get(0) + viewport.get(2)) / 2; float f1 = (viewport.get(1) + viewport.get(3)) / 2; float x = Mouse.getX(); float y = Mouse.getY(); // TODO: Minecraft seems to instist to have this winZ re-created at // each frame - looks like a memory leak to me but I couldn't use a // static variable instead, as for the rest. FloatBuffer winZ = GLAllocation.createDirectFloatBuffer(1); GL11.glReadPixels((int) x, (int) y, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZ); GLU.gluUnProject(x, y, winZ.get(), modelviewF, projectionF, viewport, pos); diffX = pos.get(0); diffY = pos.get(1); diffZ = pos.get(2); }
@Override public void gluLookAt( GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) { org.lwjgl.util.glu.GLU.gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); }
public Point2D[] project( int tube, float[] modelMatrix, float[] projectionMatrix, int[] viewport, int step) { GLU glu = new GLU(); FloatBuffer modelbuf = BufferUtils.createFloatBuffer(16); modelbuf.put(modelMatrix); modelbuf.rewind(); FloatBuffer projbuf = BufferUtils.createFloatBuffer(16); projbuf.put(projectionMatrix); projbuf.rewind(); IntBuffer viewportbuf = BufferUtils.createIntBuffer(4); viewportbuf.put(viewport); viewportbuf.rewind(); Point2D[] projectedSegments = new Point2D[(int) Math.ceil(tubes[tube].segments.length / (double) step)]; int cnt = 0; for (int j = 0; j < tubes[tube].segments.length; j = j + step) { FloatBuffer result = BufferUtils.createFloatBuffer(3); glu.gluProject( tubes[tube].segments[j].x, tubes[tube].segments[j].y, tubes[tube].segments[j].z, modelbuf, projbuf, viewportbuf, result); Point2D p = new Point2D.Double(result.get(0), viewport[3] - result.get(1) - 1); projectedSegments[cnt++] = p; } return projectedSegments; }
/** Initialisation de la fenêtre OpenGl, de la camera et des textures. */ public final void initGL() { // Création de la fenetre try { if (Setting.getFullScreen()) { Display.setDisplayModeAndFullscreen( new DisplayMode(Setting.get3DWidth(), Setting.get3DHeight())); } else { Display.setDisplayMode(new DisplayMode(Setting.get3DWidth(), Setting.get3DHeight())); } Display.setTitle("Visualisation 3D"); Display.sync(Setting.getFps()); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } float fAspect = (float) Setting.getWWidth() / (float) Setting.getWHeight(); GL11.glViewport(0, 0, Setting.getWWidth(), Setting.getWHeight()); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective(45.0f, fAspect, 1.0f, 1000.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glEnable(GL11.GL_CULL_FACE); // Initialisation de la Camera camera = new Camera("3D"); camera.init(); camera.yaw(140.0f); camera.pitch(20.0f); // Récupération des textures textures = new Textures(); textures.init(); textures.loadTexture(); wind = new Wind(); matrice.loadImg(); }
private void doEye() { int mouseX = Mouse.getX(); int mouseY = Mouse.getY(); FloatBuffer modelview = BufferUtils.createFloatBuffer(16); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview); FloatBuffer projection = BufferUtils.createFloatBuffer(16); GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection); IntBuffer viewport = BufferUtils.createIntBuffer(16); GL11.glGetInteger(GL11.GL_VIEWPORT, viewport); float winX = mouseX; float winY = viewport.get(3) - mouseY; FloatBuffer winZBuffer = BufferUtils.createFloatBuffer(1); GL11.glReadPixels(mouseX, mouseY, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZBuffer); float winZ = winZBuffer.get(0); FloatBuffer pos = BufferUtils.createFloatBuffer(3); GLU.gluUnProject(winX, winY, winZ, modelview, projection, viewport, pos); mEyeRay = new Point3f(pos.get(0), pos.get(1), pos.get(2)); }
private void recreate() { id = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, format.bytes); ByteBuffer data = BufferUtils.createByteBuffer(size.getWidth() * size.getHeight() * format.bytes); if (mipmap) { GLU.gluBuild2DMipmaps( GL11.GL_TEXTURE_2D, format.glInternalFormat, size.getWidth(), size.getHeight(), format.glFormat, GL11.GL_UNSIGNED_BYTE, data); } else { GL11.glTexImage2D( GL11.GL_TEXTURE_2D, 0, format.glInternalFormat, size.getWidth(), size.getHeight(), 0, format.glFormat, GL11.GL_UNSIGNED_BYTE, data); } GLUtil.checkGLError(); for (Texture t : residentTextures) { RectanglePacker.Rectangle rpr = packer.findRectangle(t.getSourceImage()); if (rpr != null) { writeToTexture(rpr, t.getSourceImage().getData()); } } regenerateMipmaps(); }
@Override public void draw() { GL11.glClearColor(0.8f, 0.8f, 0.8f, 0.0f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); GL11.glLoadIdentity(); GLU.gluLookAt(5.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); GL11.glRotatef(rot, 0.0f, 1.0f, 0.0f); GL11.glRotatef(rot2, 1.0f, 0.0f, 0.0f); drawer.draw(); Keyboard.poll(); while (Keyboard.next()) { if (Keyboard.getEventKeyState()) { if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { return; } if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT) { rot -= 15.0f; } if (Keyboard.getEventKey() == Keyboard.KEY_LEFT) { rot += 15.0f; } if (Keyboard.getEventKey() == Keyboard.KEY_UP) { rot2 -= 15.0f; } if (Keyboard.getEventKey() == Keyboard.KEY_DOWN) { rot2 += 15.0f; } if (Keyboard.getEventKey() == Keyboard.KEY_T) { if (renderMode == GL11.GL_POLYGON) { renderMode = GL11.GL_LINE_LOOP; } else { renderMode = GL11.GL_POLYGON; } } } } }
/** Generates the specified number of display lists and returns the first index. */ public static synchronized int generateDisplayLists(int range) { int i = GlStateManager.glGenLists(range); if (i == 0) { int j = GlStateManager.glGetError(); String s = "No error code reported"; if (j != 0) { s = GLU.gluErrorString(j); } throw new IllegalStateException( "glGenLists returned an ID of 0 for a count of " + range + ", GL error (" + j + "): " + s); } else { return i; } }
// *************************************************************************** // initGL // *************************************************************************** private static boolean initGL() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // Calculate the aspect ratio of the window GLU.gluPerspective(45.0f, ((float) targetWidth) / ((float) targetHeight), 0.1f, 100.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping (NEW) GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1.0f); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); return true; }
public static void init(VorxelSettings set, Geode gamep) { world = new World(); game = gamep; try { DisplayMode d[] = Display.getAvailableDisplayModes(); DisplayMode displayMode = d[0]; Display.setDisplayMode(displayMode); Display.create(); Mouse.create(); Keyboard.create(); GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background GL11.glClearDepth(1.0); // Depth Buffer Setup GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix GL11.glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window GLU.gluPerspective( 45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 100.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix // Really Nice Perspective Calculations GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); TextureHelper.init(); Cube.dirt.texture = new VTex(4); Cube.grass.texture = Cube.dirt.texture; Cube.grass.toptexture = new VTex(1); Mouse.setGrabbed(true); world.createSpawn(); } catch (LWJGLException e) { e.printStackTrace(); } }
public static int loadImage(BufferedImage bufferedImage) { try { short width = (short) bufferedImage.getWidth(); short height = (short) bufferedImage.getHeight(); // textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24; int bpp = (byte) bufferedImage.getColorModel().getPixelSize(); ByteBuffer byteBuffer; DataBuffer db = bufferedImage.getData().getDataBuffer(); if (db instanceof DataBufferInt) { int intI[] = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData(); byte newI[] = new byte[intI.length * 4]; for (int i = 0; i < intI.length; i++) { byte b[] = intToByteArray(intI[i]); int newIndex = i * 4; newI[newIndex] = b[1]; newI[newIndex + 1] = b[2]; newI[newIndex + 2] = b[3]; newI[newIndex + 3] = b[0]; } byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)) .order(ByteOrder.nativeOrder()) .put(newI); } else { byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)) .order(ByteOrder.nativeOrder()) .put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); } byteBuffer.flip(); int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA; IntBuffer textureId = BufferUtils.createIntBuffer(1); ; GL11.glGenTextures(textureId); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0)); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); GLU.gluBuild2DMipmaps( GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer); return textureId.get(0); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } return -1; }
public void display() { GL11.glViewport(0, 0, width, height); GL11.glClearColor(0.5f, 0.5f, 0.5f, 0.1f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float widthHeightRatio = width / height; GLU.gluPerspective(45, widthHeightRatio, 1, 1000); GLU.gluLookAt( player.getX(), player.getY(), player.getZ(), player.getCamX(), player.getCamY(), player.getCamZ(), 0, 1, 0); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); // Level GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glEnable(GL11.GL_DEPTH_TEST); for (byte i = 0; i < level.getSizeX(); i += 1) { for (byte j = 0; j < level.getSizeY(); j += 1) { for (byte k = 0; k < level.getSizeZ(); k += 1) { if (level.getCubeName(i, j, k).equals(Cube.CUBE_BOMB)) { objects.DrawCubeBomb(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION)) { objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION_HIDE_EXIT)) { objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION_HIDE_ITEM)) { objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_HEALTH)) { objects.DrawCubeItemHealth(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_XTRA_BOMB)) { objects.DrawCubeItemXtraBomb(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_BOMB_RANGE)) { objects.DrawCubeItemBombRange(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_BOMB_STRENGTH)) { objects.DrawCubeItemBombStrength(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_PORTAL)) { objects.DrawCubeItemPortal(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_DOUBLE_SCORE)) { objects.DrawCubeItemDoubleScore(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_SOLID)) { objects.DrawCubeSolid(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OUTSIDE)) { objects.DrawCubeOutside(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OBSTACLE)) { objects.DrawCubeObstacle(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OBSTACLE_HIDE_EXIT)) { objects.DrawCubeObstacle(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXIT)) { objects.DrawCubeExit(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_SOLID_RAMP)) { objects.DrawCubeRamp(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); // Menüwürfel } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_NEW_GAME)) { objects.DrawMenuCubeNewGame(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_NEW_GAME_GRAVITY)) { objects.DrawMenuCubeNewGameGravity( i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_EXIT_PROGRAM)) { objects.DrawMenuCubeExitProgram(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_MULTI)) { objects.DrawMenuCubeMulti(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_SERVER)) { objects.DrawMenuCubeServer(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_OPTIONS)) { objects.DrawMenuCubeOptions(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_LOAD_LEVEL)) { objects.DrawMenuCubeLoadLevel(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } } } } if (listPlayer != null) { for (int i = 0; i < listPlayer.size(); i++) { if (listPlayer.get(i).getNumber() != player.getNumber()) { objects.DrawPlayer( listPlayer.get(i).getX() - (SIZE_OF_CUBE / 2), listPlayer.get(i).getY() - (SIZE_OF_CUBE / 2), listPlayer.get(i).getZ() - (SIZE_OF_CUBE / 2)); } } } GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // GL11.glOrtho(-CLIPSIZE, +CLIPSIZE, -CLIPSIZE, +CLIPSIZE, -CLIPSIZE * // 100.0f, +CLIPSIZE * 100.0f); // GL11.glOrtho(-CLIPSIZE, +CLIPSIZE, -CLIPSIZE, +CLIPSIZE, -CLIPSIZE, // +CLIPSIZE); GL11.glOrtho( -Window.width / 2, +Window.width / 2, -Window.height / 2, +Window.height / 2, -CLIPSIZE, +CLIPSIZE); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); // GL11.glTranslatef(1f, 1f, 0.0f); GL11.glDisable(GL11.GL_DEPTH_TEST); hud.renderHUD(); GL11.glFlush(); }
/** Draws the main menu panorama */ private void drawPanorama(int par1, int par2, float par3) { Tessellator var4 = Tessellator.instance; GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glLoadIdentity(); GLU.gluPerspective(120.0F, 1.0F, 0.05F, 10.0F); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F); GL11.glEnable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDepthMask(false); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); byte var5 = 8; for (int var6 = 0; var6 < var5 * var5; ++var6) { GL11.glPushMatrix(); float var7 = ((float) (var6 % var5) / (float) var5 - 0.5F) / 64.0F; float var8 = ((float) (var6 / var5) / (float) var5 - 0.5F) / 64.0F; float var9 = 0.0F; GL11.glTranslatef(var7, var8, var9); GL11.glRotatef( MathHelper.sin(((float) this.panoramaTimer + par3) / 400.0F) * 25.0F + 20.0F, 1.0F, 0.0F, 0.0F); GL11.glRotatef(-((float) this.panoramaTimer + par3) * 0.1F, 0.0F, 1.0F, 0.0F); for (int var10 = 0; var10 < 6; ++var10) { GL11.glPushMatrix(); if (var10 == 1) { GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); } if (var10 == 2) { GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); } if (var10 == 3) { GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); } if (var10 == 4) { GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F); } if (var10 == 5) { GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F); } this.mc.renderEngine.func_98187_b(titlePanoramaPaths[var10]); var4.startDrawingQuads(); var4.setColorRGBA_I(16777215, 255 / (var6 + 1)); float var11 = 0.0F; var4.addVertexWithUV(-1.0D, -1.0D, 1.0D, (double) (0.0F + var11), (double) (0.0F + var11)); var4.addVertexWithUV(1.0D, -1.0D, 1.0D, (double) (1.0F - var11), (double) (0.0F + var11)); var4.addVertexWithUV(1.0D, 1.0D, 1.0D, (double) (1.0F - var11), (double) (1.0F - var11)); var4.addVertexWithUV(-1.0D, 1.0D, 1.0D, (double) (0.0F + var11), (double) (1.0F - var11)); var4.draw(); GL11.glPopMatrix(); } GL11.glPopMatrix(); GL11.glColorMask(true, true, true, false); } var4.setTranslation(0.0D, 0.0D, 0.0D); GL11.glColorMask(true, true, true, true); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPopMatrix(); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glEnable(GL11.GL_DEPTH_TEST); }
protected void func_74185_a(float p_74185_1_, int p_74185_2_, int p_74185_3_) { int var4 = this.field_73882_e.field_71446_o.func_78341_b("/gui/enchant.png"); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.field_73882_e.field_71446_o.func_78342_b(var4); int var5 = (this.field_73880_f - this.field_74194_b) / 2; int var6 = (this.field_73881_g - this.field_74195_c) / 2; this.func_73729_b(var5, var6, 0, 0, this.field_74194_b, this.field_74195_c); GL11.glPushMatrix(); GL11.glMatrixMode(5889); GL11.glPushMatrix(); GL11.glLoadIdentity(); ScaledResolution var7 = new ScaledResolution( this.field_73882_e.field_71474_y, this.field_73882_e.field_71443_c, this.field_73882_e.field_71440_d); GL11.glViewport( (var7.func_78326_a() - 320) / 2 * var7.func_78325_e(), (var7.func_78328_b() - 240) / 2 * var7.func_78325_e(), 320 * var7.func_78325_e(), 240 * var7.func_78325_e()); GL11.glTranslatef(-0.34F, 0.23F, 0.0F); GLU.gluPerspective(90.0F, 1.3333334F, 9.0F, 80.0F); float var8 = 1.0F; GL11.glMatrixMode(5888); GL11.glLoadIdentity(); RenderHelper.func_74519_b(); GL11.glTranslatef(0.0F, 3.3F, -16.0F); GL11.glScalef(var8, var8, var8); float var9 = 5.0F; GL11.glScalef(var9, var9, var9); GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); this.field_73882_e.field_71446_o.func_78342_b( this.field_73882_e.field_71446_o.func_78341_b("/item/book.png")); GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F); float var10 = this.field_74208_u + (this.field_74209_t - this.field_74208_u) * p_74185_1_; GL11.glTranslatef((1.0F - var10) * 0.2F, (1.0F - var10) * 0.1F, (1.0F - var10) * 0.25F); GL11.glRotatef(-(1.0F - var10) * 90.0F - 90.0F, 0.0F, 1.0F, 0.0F); GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F); float var11 = this.field_74212_q + (this.field_74213_p - this.field_74212_q) * p_74185_1_ + 0.25F; float var12 = this.field_74212_q + (this.field_74213_p - this.field_74212_q) * p_74185_1_ + 0.75F; var11 = (var11 - (float) MathHelper.func_76140_b((double) var11)) * 1.6F - 0.3F; var12 = (var12 - (float) MathHelper.func_76140_b((double) var12)) * 1.6F - 0.3F; if (var11 < 0.0F) { var11 = 0.0F; } if (var12 < 0.0F) { var12 = 0.0F; } if (var11 > 1.0F) { var11 = 1.0F; } if (var12 > 1.0F) { var12 = 1.0F; } GL11.glEnable('\u803a'); field_74206_w.func_78088_a((Entity) null, 0.0F, var11, var12, var10, 0.0F, 0.0625F); GL11.glDisable('\u803a'); RenderHelper.func_74518_a(); GL11.glMatrixMode(5889); GL11.glViewport(0, 0, this.field_73882_e.field_71443_c, this.field_73882_e.field_71440_d); GL11.glPopMatrix(); GL11.glMatrixMode(5888); GL11.glPopMatrix(); RenderHelper.func_74518_a(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.field_73882_e.field_71446_o.func_78342_b(var4); EnchantmentNameParts.field_78061_a.func_78058_a(this.field_74215_y.field_75166_f); for (int var13 = 0; var13 < 3; ++var13) { String var14 = EnchantmentNameParts.field_78061_a.func_78057_a(); this.field_73735_i = 0.0F; this.field_73882_e.field_71446_o.func_78342_b(var4); int var15 = this.field_74215_y.field_75167_g[var13]; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); if (var15 == 0) { this.func_73729_b(var5 + 60, var6 + 14 + 19 * var13, 0, 185, 108, 19); } else { String var16 = "" + var15; FontRenderer var17 = this.field_73882_e.field_71464_q; int var18 = 6839882; if (this.field_73882_e.field_71439_g.field_71068_ca < var15 && !this.field_73882_e.field_71439_g.field_71075_bZ.field_75098_d) { this.func_73729_b(var5 + 60, var6 + 14 + 19 * var13, 0, 185, 108, 19); var17.func_78279_b( var14, var5 + 62, var6 + 16 + 19 * var13, 104, (var18 & 16711422) >> 1); var17 = this.field_73882_e.field_71466_p; var18 = 4226832; var17.func_78261_a( var16, var5 + 62 + 104 - var17.func_78256_a(var16), var6 + 16 + 19 * var13 + 7, var18); } else { int var19 = p_74185_2_ - (var5 + 60); int var20 = p_74185_3_ - (var6 + 14 + 19 * var13); if (var19 >= 0 && var20 >= 0 && var19 < 108 && var20 < 19) { this.func_73729_b(var5 + 60, var6 + 14 + 19 * var13, 0, 204, 108, 19); var18 = 16777088; } else { this.func_73729_b(var5 + 60, var6 + 14 + 19 * var13, 0, 166, 108, 19); } var17.func_78279_b(var14, var5 + 62, var6 + 16 + 19 * var13, 104, var18); var17 = this.field_73882_e.field_71466_p; var18 = 8453920; var17.func_78261_a( var16, var5 + 62 + 104 - var17.func_78256_a(var16), var6 + 16 + 19 * var13 + 7, var18); } } } }