List of usage examples for org.lwjgl.opengl GL11 glTexParameterf
public static void glTexParameterf(@NativeType("GLenum") int target, @NativeType("GLenum") int pname, @NativeType("GLfloat") float param)
From source file:com.grillecube.engine.opengl.object.GLTexture.java
public void parameterf(int target, int pname, float param) { GL11.glTexParameterf(target, pname, param); }
From source file:com.gundogstudios.modules.DesktopGL11.java
License:Open Source License
public final void glTexParameterf(int target, int pname, float param) { GL11.glTexParameterf(target, pname, param); }
From source file:com.mtbs3d.minecrift.FBOParams.java
License:LGPL
public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType, int fboWidth, int fboHeight) throws Exception { Minecraft mc = Minecraft.getMinecraft(); _textureType = textureType;//from w ww . j a v a 2s . com if (fboSupport == FBO_SUPPORT.USE_EXT_UNKNOWN) { // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer. try { _frameBufferId = GL30.glGenFramebuffers(); fboSupport = FBO_SUPPORT.USE_GL30; } catch (IllegalStateException ex) { System.out.println( "[Minecrift] FBO creation: GL30.glGenFramebuffers not supported. Attempting to use EXTFramebufferObject.glGenFramebuffersEXT"); fboSupport = FBO_SUPPORT.USE_EXT; try { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } catch (IllegalStateException ex1) { System.out.println( "[Minecrift] FBO creation: EXTFramebufferObject.glGenFramebuffersEXT not supported, FBO creation failed."); throw ex1; } } } else if (fboSupport == FBO_SUPPORT.USE_GL30) { _frameBufferId = GL30.glGenFramebuffers(); } else { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } if (fboSupport == FBO_SUPPORT.USE_GL30) { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = GL30.glGenRenderbuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId); checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureType, _colorTextureId, 0); checkGLError("FBO bind texture framebuffer"); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, _depthRenderBufferId); // bind the depth renderbuffer GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, _depthRenderBufferId); checkGLError("FBO bind depth framebuffer"); } else { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId); checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, textureType, _colorTextureId, 0); checkGLError("FBO bind texture framebuffer"); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); // bind the depth renderbuffer EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); checkGLError("FBO bind depth framebuffer"); } if (!checkFramebufferStatus()) { // OK, if we have an error here - then throw an exception System.out.println("[Minecrift] FAILED to create framebuffer!!"); throw new Exception("Failed to create framebuffer"); } }
From source file:com.mtbs3d.minecrift.render.FBOParams.java
License:LGPL
public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType, int fboWidth, int fboHeight) throws Exception { Minecraft mc = Minecraft.getMinecraft(); _textureType = textureType;/*from w w w. j av a 2 s . c o m*/ if (fboSupport == FBO_SUPPORT.USE_EXT_UNKNOWN) { // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer. try { _frameBufferId = GL30.glGenFramebuffers(); fboSupport = FBO_SUPPORT.USE_GL30; } catch (IllegalStateException ex) { System.out.println( "[Minecrift] FBO creation: GL30.glGenFramebuffers not supported. Attempting to use EXTFramebufferObject.glGenFramebuffersEXT"); fboSupport = FBO_SUPPORT.USE_EXT; try { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } catch (IllegalStateException ex1) { System.out.println( "[Minecrift] FBO creation: EXTFramebufferObject.glGenFramebuffersEXT not supported, FBO creation failed."); throw ex1; } } } else if (fboSupport == FBO_SUPPORT.USE_GL30) { _frameBufferId = GL30.glGenFramebuffers(); } else { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } if (fboSupport == FBO_SUPPORT.USE_GL30) { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = GL30.glGenRenderbuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId); mc.checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); mc.checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); //System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureType, _colorTextureId, 0); mc.checkGLError("FBO bind texture framebuffer"); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, _depthRenderBufferId); // bind the depth renderbuffer GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, _depthRenderBufferId); mc.checkGLError("FBO bind depth framebuffer"); } else { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId); mc.checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); mc.checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); //System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, textureType, _colorTextureId, 0); mc.checkGLError("FBO bind texture framebuffer"); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); // bind the depth renderbuffer EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); mc.checkGLError("FBO bind depth framebuffer"); } if (!checkFramebufferStatus()) { // OK, if we have an error here - then throw an exception System.out.println("[Minecrift] FAILED to create framebuffer!!"); throw new Exception("Failed to create framebuffer"); } }
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; }/*from ww w . j av 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.redthirddivision.quad.rendering.materials.Texture.java
License:Apache License
private TextureManager loadTexture(String path, String root) { // String[] splitArray = path.split("\\."); // String extension = splitArray[splitArray.length - 1]; File file = null;/* w w w. ja v a 2 s .c o m*/ BufferedImage image = null; System.out.println("Attempting to load a new texture: <" + root + "/" + path + ">"); file = new File(root + "/" + path + ".png"); try { image = ImageIO.read(file); } catch (IOException e) { System.err.println("Could not find texture: <" + root + "/" + path + ">"); return textures.get(MISSING_TEXTURE_FILE); } try { int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth()); ByteBuffer buffer = Util.createByteBuffer(image.getWidth() * image.getHeight() * 4); boolean hasAlpha = image.getColorModel().hasAlpha(); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int pixel = pixels[y * image.getWidth() + x]; buffer.put((byte) ((pixel >> 16) & 0xFF)); buffer.put((byte) ((pixel >> 8) & 0xFF)); buffer.put((byte) ((pixel) & 0xFF)); if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF)); else buffer.put((byte) 0xFF); } } buffer.flip(); System.out.println("Succesfully loaded texture from file: <" + file.getPath() + ">"); TextureManager result = new TextureManager(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, result.getID()); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); return result; } catch (Exception e) { System.err.println("Could not load texture: <" + path + ".png>"); System.exit(1); } return null; }
From source file:com.samrj.devil.gl.Texture.java
License:Open Source License
/** * Sets the given parameter to the given float for this texture. The texture * must be bound./*w w w .jav a 2 s.c o m*/ * * @param param The OpenGL texture parameter to set. * @param value The value to set the parameter to. * @return This texture. */ public final T paramf(int param, float value) { if (!isBound()) throw new IllegalStateException("Texture must be bound."); GL11.glTexParameterf(target, param, value); return getThis(); }
From source file:com.sriramramani.droid.inspector.ui.InspectorCanvas.java
License:Mozilla Public License
private int bindTexture(Node node, String imageData) { int textureId = GL11.glGenTextures(); byte[] bitmap = Base64.decodeBase64(imageData); try {//from ww w . ja va2 s . co m PNGDecoder decoder = new PNGDecoder(new ByteArrayInputStream(bitmap)); int width = decoder.getWidth(); int height = decoder.getHeight(); ByteBuffer buffer = ByteBuffer.allocateDirect(4 * width * height); decoder.decode(buffer, width * 4, Format.RGBA); buffer.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); } catch (IOException e) { e.printStackTrace(); } return textureId; }
From source file:com.xrbpowered.gl.examples.GLBasicTerrain.java
License:Open Source License
@Override protected void setupResources() { super.setupResources(); specular = new Texture("ice2a.jpg"); diffuse = new Texture("ice1a2.jpg"); float anis = GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); System.out.printf("Max anisotropy: %.1f\n", anis); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, anis); normal = new Texture("ice_n.jpg"); createTerrain();//w w w. j a va 2 s . c o m water = FastMeshBuilder.plane(64f, 4, 32, StandardShader.standardVertexInfo, null); for (int x = 0; x < 3; x++) for (int y = 0; y < 3; y++) { waterActor[x][y] = StaticMeshActor.make(scene, water, StandardShader.getInstance(), BufferTexture.createPlainColor(4, 4, new Color(0.4f, 0.5f, 0.65f)), plainSpecularTexture, plainNormalTexture); waterActor[x][y].position.set((x - 1) * CHUNK_SIZE, 0f, (y - 1) * CHUNK_SIZE); waterActor[x][y].updateTransform(); } // pickObjects = new StaticMesh[] {null, terrain}; CLEAR_COLOR = new Color(0.7f, 0.75f, 0.82f); StandardShader.environment.setFog(0f, 50f, new Vector4f(0.7f, 0.75f, 0.82f, 1f)); StandardShader.environment.ambientColor.set(0.05f, 0.1f, 0.2f); StandardShader.environment.lightColor.set(0.9f, 0.85f, 0.8f); lightActor.rotation.x = (float) Math.PI / 6f; lightActor.updateTransform(); }
From source file:com.xrbpowered.gl.res.textures.Texture.java
License:Open Source License
public static void setProperties(int textureType, boolean wrap, boolean filter, int anisotropy) { GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_WRAP_S, wrap ? GL11.GL_REPEAT : GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_WRAP_T, wrap ? GL11.GL_REPEAT : GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_MAG_FILTER, filter ? GL11.GL_LINEAR : GL11.GL_NEAREST); GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_MIN_FILTER, filter ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST); if (filter) { GL30.glGenerateMipmap(textureType); if (anisotropy > 1) { GL11.glTexParameterf(textureType, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);//from ww w . j av a2s. c o m } } }