List of usage examples for org.lwjgl.opengl GL11 glTexImage2D
public static void glTexImage2D(@NativeType("GLenum") int target, @NativeType("GLint") int level, @NativeType("GLint") int internalformat, @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLint") int border, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @Nullable @NativeType("void const *") double[] pixels)
From source file:kuake2.render.lwjgl.Draw.java
License:Open Source License
protected void Draw_StretchRaw(int x, int y, int w, int h, int cols, int rows, byte[] data) { int i, j, trows; int sourceIndex; int frac, fracstep; float hscale; int row;/* www .j a v a2 s.c o m*/ float t; GL_Bind(0); if (rows <= 256) { hscale = 1; trows = rows; } else { hscale = rows / 256.0f; trows = 256; } t = rows * hscale / 256; if (!qglColorTableEXT) { //int[] image32 = new int[256*256]; image32.clear(); int destIndex = 0; for (i = 0; i < trows; i++) { row = (int) (i * hscale); if (row > rows) break; sourceIndex = cols * row; destIndex = i * 256; fracstep = cols * 0x10000 / 256; frac = fracstep >> 1; for (j = 0; j < 256; j++) { image32.put(destIndex + j, r_rawpalette[data[sourceIndex + (frac >> 16)] & 0xff]); frac += fracstep; } } GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, gl_tex_solid_format, 256, 256, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image32); } else { //byte[] image8 = new byte[256*256]; image8.clear(); int destIndex = 0; ; for (i = 0; i < trows; i++) { row = (int) (i * hscale); if (row > rows) break; sourceIndex = cols * row; destIndex = i * 256; fracstep = cols * 0x10000 / 256; frac = fracstep >> 1; for (j = 0; j < 256; j++) { image8.put(destIndex + j, data[sourceIndex + (frac >> 16)]); frac += fracstep; } } GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0, GL11.GL_COLOR_INDEX, GL11.GL_UNSIGNED_BYTE, image8); } 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); if ((gl_config.renderer == GL_RENDERER_MCD) || ((gl_config.renderer & GL_RENDERER_RENDITION) != 0)) GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0, 0); GL11.glVertex2f(x, y); GL11.glTexCoord2f(1, 0); GL11.glVertex2f(x + w, y); GL11.glTexCoord2f(1, t); GL11.glVertex2f(x + w, y + h); GL11.glTexCoord2f(0, t); GL11.glVertex2f(x, y + h); GL11.glEnd(); if ((gl_config.renderer == GL_RENDERER_MCD) || ((gl_config.renderer & GL_RENDERER_RENDITION) != 0)) GL11.glEnable(GL11.GL_ALPHA_TEST); }
From source file:kuake2.render.lwjgl.Image.java
License:Open Source License
boolean GL_Upload32(int[] data, int width, int height, boolean mipmap) { int samples;// w w w . jav a 2 s. c o m int scaled_width, scaled_height; int i, c; int comp; Arrays.fill(scaled, 0); // Arrays.fill(paletted_texture, (byte)0); paletted_texture.clear(); for (int j = 0; j < 256 * 256; j++) paletted_texture.put(j, (byte) 0); uploaded_paletted = false; for (scaled_width = 1; scaled_width < width; scaled_width <<= 1) ; if (gl_round_down.value > 0.0f && scaled_width > width && mipmap) scaled_width >>= 1; for (scaled_height = 1; scaled_height < height; scaled_height <<= 1) ; if (gl_round_down.value > 0.0f && scaled_height > height && mipmap) scaled_height >>= 1; // let people sample down the world textures for speed if (mipmap) { scaled_width >>= (int) gl_picmip.value; scaled_height >>= (int) gl_picmip.value; } // don't ever bother with >256 textures if (scaled_width > 256) scaled_width = 256; if (scaled_height > 256) scaled_height = 256; if (scaled_width < 1) scaled_width = 1; if (scaled_height < 1) scaled_height = 1; upload_width = scaled_width; upload_height = scaled_height; if (scaled_width * scaled_height > 256 * 256) Com.Error(Defines.ERR_DROP, "GL_Upload32: too big"); // scan the texture for any non-255 alpha c = width * height; samples = gl_solid_format; for (i = 0; i < c; i++) { if ((data[i] & 0xff000000) != 0xff000000) { samples = gl_alpha_format; break; } } if (samples == gl_solid_format) comp = gl_tex_solid_format; else if (samples == gl_alpha_format) comp = gl_tex_alpha_format; else { VID.Printf(Defines.PRINT_ALL, "Unknown number of texture components " + samples + '\n'); comp = samples; } // simulates a goto try { if (scaled_width == width && scaled_height == height) { if (!mipmap) { if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f && samples == gl_solid_format) { uploaded_paletted = true; GL_BuildPalettedTexture(paletted_texture, data, scaled_width, scaled_height); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL11.GL_COLOR_INDEX, GL11.GL_UNSIGNED_BYTE, paletted_texture); } else { tex.rewind(); tex.put(data); tex.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, tex); } //goto done; throw gotoDone; } //memcpy (scaled, data, width*height*4); were bytes System.arraycopy(data, 0, scaled, 0, width * height); } else GL_ResampleTexture(data, width, height, scaled, scaled_width, scaled_height); GL_LightScaleTexture(scaled, scaled_width, scaled_height, !mipmap); if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f && (samples == gl_solid_format)) { uploaded_paletted = true; GL_BuildPalettedTexture(paletted_texture, scaled, scaled_width, scaled_height); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL11.GL_COLOR_INDEX, GL11.GL_UNSIGNED_BYTE, paletted_texture); } else { tex.rewind(); tex.put(scaled); tex.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, tex); } if (mipmap) { int miplevel; miplevel = 0; while (scaled_width > 1 || scaled_height > 1) { GL_MipMap(scaled, scaled_width, scaled_height); scaled_width >>= 1; scaled_height >>= 1; if (scaled_width < 1) scaled_width = 1; if (scaled_height < 1) scaled_height = 1; miplevel++; if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f && samples == gl_solid_format) { uploaded_paletted = true; GL_BuildPalettedTexture(paletted_texture, scaled, scaled_width, scaled_height); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, miplevel, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL11.GL_COLOR_INDEX, GL11.GL_UNSIGNED_BYTE, paletted_texture); } else { tex.rewind(); tex.put(scaled); tex.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, miplevel, comp, scaled_width, scaled_height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, tex); } } } // label done: } catch (Throwable e) { // replaces label done } if (mipmap) { GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, gl_filter_min); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, gl_filter_max); } else { GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, gl_filter_max); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, gl_filter_max); } return (samples == gl_alpha_format); }
From source file:kuake2.render.lwjgl.Image.java
License:Open Source License
boolean GL_Upload8(byte[] data, int width, int height, boolean mipmap, boolean is_sky) { Arrays.fill(trans, 0);// ww w . j a v a2 s . com int s = width * height; if (s > trans.length) Com.Error(Defines.ERR_DROP, "GL_Upload8: too large"); if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f && is_sky) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, width, height, 0, GL11.GL_COLOR_INDEX, GL11.GL_UNSIGNED_BYTE, ByteBuffer.wrap(data)); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, gl_filter_max); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, gl_filter_max); // TODO check this return false; } else { int p; for (int i = 0; i < s; i++) { p = data[i] & 0xff; trans[i] = d_8to24table[p]; if (p == 255) { // transparent, so scan around for another color // to avoid alpha fringes // FIXME: do a full flood fill so mips work... if (i > width && (data[i - width] & 0xff) != 255) p = data[i - width] & 0xff; else if (i < s - width && (data[i + width] & 0xff) != 255) p = data[i + width] & 0xff; else if (i > 0 && (data[i - 1] & 0xff) != 255) p = data[i - 1] & 0xff; else if (i < s - 1 && (data[i + 1] & 0xff) != 255) p = data[i + 1] & 0xff; else p = 0; // copy rgb components // ((byte *)&trans[i])[0] = ((byte *)&d_8to24table[p])[0]; // ((byte *)&trans[i])[1] = ((byte *)&d_8to24table[p])[1]; // ((byte *)&trans[i])[2] = ((byte *)&d_8to24table[p])[2]; trans[i] = d_8to24table[p] & 0x00FFFFFF; // only rgb } } return GL_Upload32(trans, width, height, mipmap); } }
From source file:kuake2.render.lwjgl.Surf.java
License:Open Source License
/** * LM_UploadBlock// w w w . ja v a 2s . co m * * @param dynamic */ void LM_UploadBlock(boolean dynamic) { int texture = (dynamic) ? 0 : gl_lms.current_lightmap_texture; GL_Bind(gl_state.lightmap_textures + texture); 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); gl_lms.lightmap_buffer.rewind(); if (dynamic) { int height = 0; for (int i = 0; i < BLOCK_WIDTH; i++) { if (gl_lms.allocated[i] > height) height = gl_lms.allocated[i]; } GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, BLOCK_WIDTH, height, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, gl_lms.lightmap_buffer); } else { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, gl_lms.internal_format, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, gl_lms.lightmap_buffer); if (++gl_lms.current_lightmap_texture == MAX_LIGHTMAPS) Com.Error(Defines.ERR_DROP, "LM_UploadBlock() - MAX_LIGHTMAPS exceeded\n"); //debugLightmap(gl_lms.lightmap_buffer, 128, 128, 4); } }
From source file:kuake2.render.lwjgl.Surf.java
License:Open Source License
/** * GL_BeginBuildingLightmaps// www . j a v a 2 s . c o m */ void GL_BeginBuildingLightmaps(model_t m) { // static lightstyle_t lightstyles[MAX_LIGHTSTYLES]; int i; // init lightstyles if (lightstyles == null) { lightstyles = new lightstyle_t[Defines.MAX_LIGHTSTYLES]; for (i = 0; i < lightstyles.length; i++) { lightstyles[i] = new lightstyle_t(); } } // memset( gl_lms.allocated, 0, sizeof(gl_lms.allocated) ); Arrays.fill(gl_lms.allocated, 0); r_framecount = 1; // no dlightcache GL_EnableMultitexture(true); GL_SelectTexture(GL_TEXTURE1); /* ** setup the base lightstyles so the lightmaps won't have to be regenerated ** the first time they're seen */ for (i = 0; i < Defines.MAX_LIGHTSTYLES; i++) { lightstyles[i].rgb[0] = 1; lightstyles[i].rgb[1] = 1; lightstyles[i].rgb[2] = 1; lightstyles[i].white = 3; } r_newrefdef.lightstyles = lightstyles; if (gl_state.lightmap_textures == 0) { gl_state.lightmap_textures = TEXNUM_LIGHTMAPS; } gl_lms.current_lightmap_texture = 1; /* ** if mono lightmaps are enabled and we want to use alpha ** blending (a,1-a) then we're likely running on a 3DLabs ** Permedia2. In a perfect world we'd use a GL_ALPHA lightmap ** in order to conserve space and maximize bandwidth, however ** this isn't a perfect world. ** ** So we have to use alpha lightmaps, but stored in GL_RGBA format, ** which means we only get 1/16th the color resolution we should when ** using alpha lightmaps. If we find another board that supports ** only alpha lightmaps but that can at least support the GL_ALPHA ** format then we should change this code to use real alpha maps. */ char format = gl_monolightmap.string.toUpperCase().charAt(0); if (format == 'A') { gl_lms.internal_format = gl_tex_alpha_format; } /* ** try to do hacked colored lighting with a blended texture */ else if (format == 'C') { gl_lms.internal_format = gl_tex_alpha_format; } else if (format == 'I') { gl_lms.internal_format = GL11.GL_INTENSITY8; } else if (format == 'L') { gl_lms.internal_format = GL11.GL_LUMINANCE8; } else { gl_lms.internal_format = gl_tex_solid_format; } /* ** initialize the dynamic lightmap texture */ GL_Bind(gl_state.lightmap_textures + 0); 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, gl_lms.internal_format, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, dummy); }
From source file:loon.core.graphics.opengl.LWjglGL10.java
License:Apache License
public final void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) { GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ByteBuffer) pixels); } else if (pixels instanceof ShortBuffer) { GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ShortBuffer) pixels); } else if (pixels instanceof IntBuffer) { GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (IntBuffer) pixels); } else if (pixels instanceof FloatBuffer) { GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (FloatBuffer) pixels); } else if (pixels instanceof DoubleBuffer) { GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (DoubleBuffer) pixels); } else {/*from w ww . j a va 2 s . c o m*/ throw new RuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL"); } }
From source file:lwjake2.render.lwjgl.Surf.java
License:Open Source License
/** * GL_BeginBuildingLightmaps//w w w . j a v a 2 s.c o m */ void GL_BeginBuildingLightmaps(model_t m) { // static lightstyle_t lightstyles[MAX_LIGHTSTYLES]; int i; // init lightstyles if (lightstyles == null) { lightstyles = new lightstyle_t[Defines.MAX_LIGHTSTYLES]; for (i = 0; i < lightstyles.length; i++) { lightstyles[i] = new lightstyle_t(); } } // memset( gl_lms.allocated, 0, sizeof(gl_lms.allocated) ); Arrays.fill(gl_lms.allocated, 0); r_framecount = 1; // no dlightcache GL_EnableMultitexture(true); GL_SelectTexture(GL_TEXTURE1); /* ** setup the base lightstyles so the lightmaps won't have to be regenerated ** the first time they're seen */ for (i = 0; i < Defines.MAX_LIGHTSTYLES; i++) { lightstyles[i].rgb[0] = 1; lightstyles[i].rgb[1] = 1; lightstyles[i].rgb[2] = 1; lightstyles[i].white = 3; } r_newrefdef.lightstyles = lightstyles; if (gl_state.lightmap_textures == 0) { gl_state.lightmap_textures = TEXNUM_LIGHTMAPS; } gl_lms.current_lightmap_texture = 1; /* ** if mono lightmaps are enabled and we want to use alpha ** blending (a,1-a) then we're likely running on a 3DLabs ** Permedia2. In a perfect world we'd use a GL_ALPHA lightmap ** in order to conserve space and maximize bandwidth, however ** this isn't a perfect world. ** ** So we have to use alpha lightmaps, but stored in GL_RGBA format, ** which means we only get 1/16th the color resolution we should when ** using alpha lightmaps. If we find another board that supports ** only alpha lightmaps but that can at least support the GL_ALPHA ** format then we should change this code to use real alpha maps. */ char format = gl_monolightmap.string.toUpperCase().charAt(0); if (format == 'A') { gl_lms.internal_format = gl_tex_alpha_format; } /* ** try to do hacked colored lighting with a blended texture */ else if (format == 'C') { gl_lms.internal_format = gl_tex_alpha_format; } else if (format == 'I') { gl_lms.internal_format = GL11.GL_INTENSITY8; } else if (format == 'L') { gl_lms.internal_format = GL11.GL_LUMINANCE8; } else { gl_lms.internal_format = gl_tex_solid_format; } /* ** initialize the dynamic lightmap texture */ GL_Bind(gl_state.lightmap_textures + 0); 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, gl_lms.internal_format, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, dummy); }
From source file:main.java.com.YeAJG.game.io.FileIOHandler.java
License:Open Source License
public static int loadPNGTexture(String filename, int textureUnit) throws IOException { ByteBuffer buf = null;//ww w . j a va 2s .co m 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, PNGDecoder.RGBA); buf.flip(); in.close(); } catch (IOException e) { throw new IOException(e.getMessage()); } // 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_RGBA, 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_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); Game.exitOnGLError("loadPNGTexture"); return texId; }
From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Texture.java
License:Open Source License
@Override public void setPixelData(ByteBuffer pixels, InternalFormat format, int width, int height, boolean generateMipmaps) { ensureCreated("Texture must be created to set pixel data."); // Check if mipmaps should be generated for this texture if (generateMipmaps) { GLU.gluBuild2DMipmaps(GL_TEXTURE_2D, format.getFormat().getNumComponents(), width, height, format.getFormat().getGLConstant(), format.getDataType().getGLConstant(), pixels); } else {// w w w . j av a 2 s . co m GL11.glTexImage2D(GL_TEXTURE_2D, 0, format.getGLConstant(), width, height, 0, format.getFormat().getGLConstant(), format.getDataType().getGLConstant(), pixels); } }
From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30Texture.java
License:Open Source License
@Override public void setPixelData(ByteBuffer pixels, InternalFormat format, int width, int height, boolean generateMipmaps) { ensureCreated("Texture must be created to set pixel data."); // Upload the pixel data to the GPU GL11.glTexImage2D(GL_TEXTURE_2D, 0, format.getGLConstant(), width, height, 0, format.getFormat().getGLConstant(), format.getDataType().getGLConstant(), pixels); // Check if mipmaps should be generated for this texture if (generateMipmaps) { GL30.glGenerateMipmap(GL_TEXTURE_2D); }/* ww w . ja va 2 s . c o m*/ }