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:opengl.test.object.tivi.tivi.java
@Override protected void initVertex() { GL30.glBindVertexArray(vao);//bind vao Object[] dataInput = objLoad.Wavefront( tivi.class.getClassLoader().getResourceAsStream("opengl/test/object/tivi/tivi.obj"), 1.0f, 1.0f, 1.0f);/*from w ww. j av a 2s. co m*/ super.dataBuffer = (FloatBuffer) dataInput[0]; this.size = (int) dataInput[1]; this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, super.dataBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); IntBuffer comp = BufferUtils.createIntBuffer(1); STBImage.stbi_set_flip_vertically_on_load(1); ByteBuffer image = STBImage.stbi_load("resource/success.png", w, h, comp, 0); textureID = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); 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.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); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w.get(0), h.get(0), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); GL30.glBindVertexArray(0);//unbind vao }
From source file:org.agpu.oc.client.ClientProxy.java
@Override public int setup2DScreenTextureTarget(int w, int h) { //Generate Texture Space int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); //Generate Blank Texture GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, w, h, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_INT, (IntBuffer) null);/*from w w w. java 2 s . c o m*/ //Poor filtering. Needed! 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); System.out.println("Generated AGPU output texture"); return texture; }
From source file:org.free.jake2.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;/*w w w. jav a 2 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:org.free.jake2.render.lwjgl.Image.java
License:Open Source License
boolean GL_Upload32(int[] data, int width, int height, boolean mipmap) { int samples;/*from www.j a v 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:org.free.jake2.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);/*from w w w. jav a 2 s . c o m*/ 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; int rgb; 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:org.free.jake2.render.lwjgl.Surf.java
License:Open Source License
/** * LM_UploadBlock//from w w w . ja va 2 s . c o 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_WIDTH1; i++) { if (gl_lms.allocated[i] > height) { height = gl_lms.allocated[i]; } } GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, BLOCK_WIDTH1, 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_WIDTH1, BLOCK_HEIGHT1, 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:org.free.jake2.render.lwjgl.Surf.java
License:Open Source License
/** * GL_BeginBuildingLightmaps//from w w w . ja va 2 s. c om */ 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_WIDTH1, BLOCK_HEIGHT1, 0, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, dummy); }
From source file:org.fusfoundation.kranion.ImageLabel.java
License:Open Source License
private void buildTexture(String resource) { BufferedImage img = null;//from w ww . ja va 2 s.c om try { InputStream rstm = this.getClass().getResourceAsStream(resource); img = ImageIO.read(rstm); } catch (IOException e) { return; } try { //Create the PNGDecoder object and decode the texture to a buffer int width = img.getWidth(), height = img.getHeight(); bounds.width = width; bounds.height = height; byte buf[] = (byte[]) img.getRaster().getDataElements(0, 0, width, height, null); ByteBuffer pixelData = ByteBuffer.allocateDirect(buf.length); pixelData.put(buf, 0, buf.length); pixelData.flip(); if (texName != 0) { deleteTexture(); } //Generate and bind the texture texName = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texName); //Upload the buffer's content to the VRAM GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixelData); //Apply filters 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.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.glBindTexture(GL11.GL_TEXTURE_2D, 0); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jmangos.tools.openGL.TextureLoader.java
License:Open Source License
/** * Load a texture into OpenGL from a BufferedImage * //from w w w. j a v a 2 s.co m * @param resourceName * The location of the resource to load * @param target * The GL target to load the texture against * @param dstPixelFormat * The pixel format of the screen * @param minFilter * The minimising filter * @param magFilter * The magnification filter * @return The loaded texture * @throws IOException * Indicates a failure to access the resource */ public Texture getNMMTexture(final BufferedImage resourceimage, final int target, final int dstPixelFormat, final int minFilter, final int magFilter) throws IOException { int srcPixelFormat = 0; // create the texture ID for this texture final int textureID = createTextureID(); final Texture texture = new Texture(target, textureID); // bind this texture GL11.glBindTexture(target, textureID); final BufferedImage bufferedImage = resourceimage; texture.setWidth(bufferedImage.getWidth()); texture.setHeight(bufferedImage.getHeight()); if (bufferedImage.getColorModel().hasAlpha()) { srcPixelFormat = GL11.GL_RGBA; } else { srcPixelFormat = GL11.GL_RGB; } // convert that image into a byte buffer of texture data final ByteBuffer textureBuffer = convertImageData(bufferedImage, texture); if (target == GL11.GL_TEXTURE_2D) { GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter); } // produce a texture from the byte buffer GL11.glTexImage2D(target, 0, dstPixelFormat, get2Fold(bufferedImage.getWidth()), get2Fold(bufferedImage.getHeight()), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); return texture; }
From source file:org.jtrfp.mtmx.internal.TextureLoader.java
License:Open Source License
@Override public ITexture load(RawImage rawImage) throws EngineException { BufferedImage bufferedImage = null; try {/*from w w w . ja va 2s. c o m*/ bufferedImage = rawImage.toImage(); } catch (FileStoreException e) { throw new EngineException("Could not convert texture image.", e); } final int type = GL11.GL_TEXTURE_2D; final int width = bufferedImage.getWidth(); final int height = bufferedImage.getHeight(); int textureId = createTextureId(); Texture texture = new Texture(type, textureId, width, height); GL11.glBindTexture(type, textureId); // really neccessary here? ByteBuffer buffer = makeByteBuffer(bufferedImage, width, height); GL11.glTexParameteri(type, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(type, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); GL11.glTexImage2D(type, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, buffer); System.out.println("Created texture " + textureId); return texture; }