Java Code Examples for org.lwjgl.opengl.GL11#glTexParameteri()
The following examples show how to use
org.lwjgl.opengl.GL11#glTexParameteri() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Base64Renderer.java From The-5zig-Mod with GNU General Public License v3.0 | 6 votes |
private void render(int x, int y, int width, int height, IResourceLocation resource, float r, float g, float b, float a) { if (dynamicImage != null) { The5zigMod.getVars().bindTexture(dynamicImage); } else { The5zigMod.getVars().bindTexture(resource); } GLUtil.color(r, g, b, a); GLUtil.disableBlend(); if (interpolateLinear) { 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_NEAREST_MIPMAP_LINEAR); } Gui.drawModalRectWithCustomSizedTexture(x, y, 0.0F, 0.0F, width, height, width, height); if (interpolateLinear) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST); } }
Example 2
Source File: Base64Renderer.java From The-5zig-Mod with MIT License | 6 votes |
private void render(int x, int y, int width, int height, IResourceLocation resource, float r, float g, float b, float a) { if (dynamicImage != null) { The5zigMod.getVars().bindTexture(dynamicImage); } else { The5zigMod.getVars().bindTexture(resource); } GLUtil.color(r, g, b, a); GLUtil.disableBlend(); if (interpolateLinear) { 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_NEAREST_MIPMAP_LINEAR); } Gui.drawModalRectWithCustomSizedTexture(x, y, 0.0F, 0.0F, width, height, width, height); if (interpolateLinear) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST); } }
Example 3
Source File: Utils.java From SkyblockAddons with MIT License | 6 votes |
/** * Draws a textured rectangle at z = 0. Args: x, y, u, v, width, height, textureWidth, textureHeight */ public void drawModalRectWithCustomSizedTexture(float x, float y, float u, float v, float width, float height, float textureWidth, float textureHeight, boolean linearTexture) { if (linearTexture) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } float f = 1.0F / textureWidth; float f1 = 1.0F / textureHeight; Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); worldrenderer.pos(x, y + height, 0.0D).tex(u * f, (v + height) * f1).endVertex(); worldrenderer.pos(x + width, y + height, 0.0D).tex((u + width) * f, (v + height) * f1).endVertex(); worldrenderer.pos(x + width, y, 0.0D).tex((u + width) * f, v * f1).endVertex(); worldrenderer.pos(x, y, 0.0D).tex(u * f, v * f1).endVertex(); tessellator.draw(); if (linearTexture) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } }
Example 4
Source File: GuiButtonIcon.java From Hyperium with GNU Lesser General Public License v3.0 | 6 votes |
/** * Draws this button to the screen. */ public void drawButton(Minecraft mc, int mouseX, int mouseY) { if (visible) { int width = 52; int height = 52; mc.getTextureManager().bindTexture(icon); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPushMatrix(); GL11.glScalef(scale, scale, scale); GlStateManager.enableBlend(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTranslatef(xPosition / scale + this.width / scale / 2, yPosition / scale + this.height / scale / 2, 0); GlStateManager.color(0, 0, 0, 1.0F); float mag = 1.25F; GlStateManager.scale(mag, mag, mag); drawTexturedModalRect(-width / 2, -height / 2, 52 * sprite, 0, width, height); GlStateManager.scale(1.0F / mag, 1.0F / mag, 1.0F / mag); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); drawTexturedModalRect(-width / 2, -height / 2, 52 * sprite, 0, width, height); GlStateManager.disableBlend(); GL11.glPopMatrix(); } }
Example 5
Source File: TextureUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public static void prepareTexture(int target, int texture, int min_mag_filter, int wrap) { GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, min_mag_filter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, min_mag_filter); if(target == GL11.GL_TEXTURE_2D) GlStateManager.bindTexture(target); else GL11.glBindTexture(target, texture); switch (target) { case GL12.GL_TEXTURE_3D: GL11.glTexParameteri(target, GL12.GL_TEXTURE_WRAP_R, wrap); case GL11.GL_TEXTURE_2D: GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_T, wrap); case GL11.GL_TEXTURE_1D: GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_S, wrap); } }
Example 6
Source File: Rendertarget.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Creates a Rendertarget with a Texture that it renders the color buffer in * and a renderbuffer that it renders the depth to. * @param width the width * @param height the height * @return the newly created Rendertarget instance */ public static Rendertarget createRTTFramebuffer(int width, int height) { int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); Rendertarget buffer = new Rendertarget(width,height); buffer.bind(); int fboTexture = buffer.textureID; GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, width, height); EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer); return buffer; }
Example 7
Source File: Rendertarget.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Creates a Rendertarget with a Texture that it renders the color buffer in * and a renderbuffer that it renders the depth to. * @param width the width * @param height the height * @return the newly created Rendertarget instance */ public static Rendertarget createRTTFramebuffer(int width, int height) { int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); Rendertarget buffer = new Rendertarget(width,height); buffer.bind(); int fboTexture = buffer.textureID; GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, width, height); EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer); return buffer; }
Example 8
Source File: ClientDynamicTexture.java From AdvancedRocketry with MIT License | 6 votes |
private void init() { //create array, every single pixel ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL); for(int i = 0; i < image.getHeight() * image.getWidth(); i++) { buffer.putInt(0x00000000); } buffer.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId()); //Just clamp to edge 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); //Scale linearly GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); }
Example 9
Source File: LWJGL15DrawContext.java From settlers-remake with MIT License | 5 votes |
/** * Sets the texture parameters, assuming that the texture was just created and is bound. */ private void setTextureParameters() { 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_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); }
Example 10
Source File: Texture.java From mapwriter with MIT License | 5 votes |
public void setTexParameters(int minFilter, int maxFilter, int textureWrap) { this.bind(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, textureWrap); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, textureWrap); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, maxFilter); }
Example 11
Source File: CurveRenderState.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Backup the current state of the relevant OpenGL state and change it to * what's needed to draw the curve. */ private RenderState saveRenderState() { RenderState state = new RenderState(); state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH); state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND); state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST); state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK); state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D); state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); GL11.glDisable(GL11.GL_POLYGON_SMOOTH); GL11.glEnable(GL11.GL_BLEND); GL14.glBlendEquation(GL14.GL_FUNC_ADD); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(true); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_TEXTURE_1D); GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL20.glUseProgram(0); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); return state; }
Example 12
Source File: CurveRenderState.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Backup the current state of the relevant OpenGL state and change it to * what's needed to draw the curve. */ private RenderState saveRenderState() { RenderState state = new RenderState(); state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH); state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND); state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST); state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK); state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D); state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE); state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); GL11.glDisable(GL11.GL_POLYGON_SMOOTH); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(true); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_TEXTURE_1D); GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL20.glUseProgram(0); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glLoadIdentity(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); return state; }
Example 13
Source File: TextureUtils.java From OpenGL-Animation with The Unlicense | 5 votes |
protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) { int texID = GL11.glGenTextures(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data.getBuffer()); if (builder.isMipmap()) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); 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_MIPMAP_LINEAR); if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0f); } } else if (builder.isNearest()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); } else { 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); } if (builder.isClampEdges()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); } else { 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.glBindTexture(GL11.GL_TEXTURE_2D, 0); return texID; }
Example 14
Source File: Texture.java From mapwriter with MIT License | 5 votes |
public void setLinearScaling(boolean enabled) { this.bind(); if (enabled) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } }
Example 15
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 4 votes |
private int loadPNGTexture(String filename, int textureUnit) { ByteBuffer buf = null; int tWidth = 0; int tHeight = 0; try { // Open the PNG file as an InputStream InputStream in = new FileInputStream(filename); // Link the PNG decoder to this stream PNGDecoder decoder = new PNGDecoder(in); // Get the width and height of the texture tWidth = decoder.getWidth(); tHeight = decoder.getHeight(); // Decode the PNG file in a ByteBuffer buf = ByteBuffer.allocateDirect( 4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); in.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } // Create a new texture object in memory and bind it int texId = GL11.glGenTextures(); GL13.glActiveTexture(textureUnit); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // All RGB bytes are aligned to each other and each component is 1 byte GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture data and generate mip maps (for scaling) GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // Setup the ST coordinate system 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); // Setup what to do when the texture has to be scaled GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); this.exitOnGLError("loadPNGTexture"); return texId; }
Example 16
Source File: SlytherClient.java From Slyther with MIT License | 4 votes |
@Override public void run() { double delta = 0; long previousTime = System.nanoTime(); long timer = System.currentTimeMillis(); int ups = 0; double nanoUpdates = 1000000000.0 / 30.0; GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); setupDisplay(); boolean doResize = false; while (!Display.isCloseRequested()) { if (Display.wasResized() && doResize) { setupDisplay(); } doResize = true; long currentTime = System.nanoTime(); double currentTickDelta = (currentTime - previousTime) / nanoUpdates; delta += currentTickDelta; frameDelta = (frameDelta + currentTickDelta) % 1.0; previousTime = currentTime; while (delta >= 1) { update(); renderHandler.update(); delta--; ups++; } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glPushMatrix(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); renderHandler.render(); fps++; if (System.currentTimeMillis() - timer > 1000) { int bytesPerSecond = 0; int packetsPerSecond = 0; if (networkManager != null) { bytesPerSecond = networkManager.bytesPerSecond; packetsPerSecond = networkManager.packetsPerSecond; networkManager.bytesPerSecond = 0; networkManager.packetsPerSecond = 0; } Display.setTitle("Slyther - FPS: " + fps + " - UPS: " + ups + " - BPS: " + bytesPerSecond + " - PPS: " + packetsPerSecond); fps = 0; timer += 1000; ups = 0; } GL11.glPopMatrix(); Display.sync(60); Display.update(); } if (networkManager != null && networkManager.isOpen()) { networkManager.closeConnection(ClientNetworkManager.SHUTDOWN_CODE, ""); } try { ConfigHandler.INSTANCE.saveConfig(CONFIGURATION_FILE, configuration); } catch (IOException e) { Log.error("Failed to save config"); Log.catching(e); } Display.destroy(); }
Example 17
Source File: LwjglTextureUtils.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static int createTexture(BufferedImage[] mips, TextureFilter filterMode) { IntBuffer buff = BufferUtils.createIntBuffer(16); buff.limit(1); GL11.glGenTextures(buff); int textureId = buff.get(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); if (filterMode == TextureFilter.NEAREST) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); } else { 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_MIPMAP_LINEAR); } GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); for (int mip=0; mip<mips.length; mip++) { BufferedImage imageData = mips[mip]; imageData = convertToGlFormat(imageData); ByteBuffer scratch = ByteBuffer.allocateDirect(4*imageData.getWidth()*imageData.getHeight()); Raster raster = imageData.getRaster(); byte data[] = (byte[])raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, mip, GL11.GL_RGBA, // Mip level & Internal format imageData.getWidth(), imageData.getHeight(), 0, // width, height, border GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format scratch); // pixel data // GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, // 0, 0, // imageData.getWidth(), imageData.getHeight(), // GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // format, type // scratch); } return textureId; }
Example 18
Source File: LwjglTextureUtils.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static int createTexture(BufferedImage imageData, TextureFilter filterMode) { imageData = convertToGlFormat(imageData); IntBuffer buff = BufferUtils.createIntBuffer(16); buff.limit(1); GL11.glGenTextures(buff); int textureId = buff.get(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); if (filterMode == TextureFilter.NEAREST) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); } else { 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.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); ByteBuffer scratch = ByteBuffer.allocateDirect(4*imageData.getWidth()*imageData.getHeight()); Raster raster = imageData.getRaster(); byte data[] = (byte[])raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, // Mip level & Internal format imageData.getWidth(), imageData.getHeight(), 0, // width, height, border GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format scratch); // pixel data GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, imageData.getWidth(), imageData.getHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // format, type scratch); return textureId; }
Example 19
Source File: ImmediateModeOGLRenderer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.opengl.renderer.SGL#glTexParameteri(int, int, int) */ public void glTexParameteri(int target, int param, int value) { GL11.glTexParameteri(target, param, value); }
Example 20
Source File: TrueTypeFont.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
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_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST); //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST); 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; }