List of usage examples for org.lwjgl.opengl GL11 glTexSubImage2D
public static void glTexSubImage2D(@NativeType("GLenum") int target, @NativeType("GLint") int level, @NativeType("GLint") int xoffset, @NativeType("GLint") int yoffset, @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @NativeType("void const *") double[] pixels)
From source file:kuake2.render.lwjgl.Surf.java
License:Open Source License
/** * LM_UploadBlock//from w w w .j a va2s .c om * * @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:loon.core.graphics.opengl.LWjglGL10.java
License:Apache License
public final void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) { GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ByteBuffer) pixels); } else if (pixels instanceof ShortBuffer) { GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ShortBuffer) pixels); } else if (pixels instanceof IntBuffer) { GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (IntBuffer) pixels); } else if (pixels instanceof FloatBuffer) { GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (FloatBuffer) pixels); } else if (pixels instanceof DoubleBuffer) { GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (DoubleBuffer) pixels); } else {//from w w w. j a v a 2s . co 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:net.minecraft.src.betterfonts.GlyphCache.java
License:Open Source License
/** * Update a portion of the current glyph cache texture using the contents of the glyphCacheImage with glTexSubImage2D(). * * @param dirty The rectangular region in glyphCacheImage that has changed and needs to be copied into the texture * * @todo Add mip-mapping support here//w ww . j a va 2s .co m * @todo Test with bilinear texture interpolation and possibly add a 1 pixel transparent border around each glyph to avoid * bleedover when interpolation is active or add a small "fudge factor" to the UV coordinates like already n FontRenderer */ private void updateTexture(Rectangle dirty) { /* Only update OpenGL texture if changes were made to the texture */ if (dirty != null) { /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */ updateImageBuffer(dirty.x, dirty.y, dirty.width, dirty.height); /* * NOTE: Since the text is drawn in white with full alpha, each pixel is always all 0s or all 1s * and there is no need to manually convert from Java's ARGB layout to OpenGLs RGBA. This avoids * having to copy into an extra byte array first; instead the int array is copied straight to a * direct int buffer. */ GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, dirty.x, dirty.y, dirty.width, dirty.height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageBuffer); } }
From source file:net.neilcsmith.praxis.video.opengl.internal.GLRenderer.java
License:Apache License
void syncPixelBufferToTexture(IntBuffer buffer, Texture texture, boolean alpha, int x, int y, int width, int height) { texture.bind();/*w w w. jav a 2 s. com*/ if (!alpha) { GL11.glPixelTransferf(GL11.GL_ALPHA_BIAS, 1); } GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buffer); if (!alpha) { GL11.glPixelTransferf(GL11.GL_ALPHA_BIAS, 0); } }
From source file:org.free.jake2.render.lwjgl.Surf.java
License:Open Source License
/** * R_RenderBrushPoly//w w w. j a v a 2s .c o m */ void R_RenderBrushPoly(msurface_t fa) { c_brush_polys++; image_t image = R_TextureAnimation(fa.texinfo); if ((fa.flags & Defines.SURF_DRAWTURB) != 0) { GL_Bind(image.texnum); // warp texture, no lightmaps GL_TexEnv(GL11.GL_MODULATE); GL11.glColor4f(gl_state.inverse_intensity, gl_state.inverse_intensity, gl_state.inverse_intensity, 1.0F); EmitWaterPolys(fa); GL_TexEnv(GL11.GL_REPLACE); return; } else { GL_Bind(image.texnum); GL_TexEnv(GL11.GL_REPLACE); } // ====== // PGM if ((fa.texinfo.flags & Defines.SURF_FLOWING) != 0) { DrawGLFlowingPoly(fa.polys); } else { DrawGLPoly(fa.polys); } // PGM // ====== // ersetzt goto boolean gotoDynamic = false; /* ** check for lightmap modification */ int maps; for (maps = 0; maps < Defines.MAXLIGHTMAPS && fa.styles[maps] != (byte) 255; maps++) { if (r_newrefdef.lightstyles[fa.styles[maps] & 0xFF].white != fa.cached_light[maps]) { gotoDynamic = true; break; } } // this is a hack from cwei if (maps == 4) { maps--; } // dynamic this frame or dynamic previously boolean is_dynamic = false; if (gotoDynamic || (fa.dlightframe == r_framecount)) { // label dynamic: if (gl_dynamic.value != 0) { if ((fa.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP)) == 0) { is_dynamic = true; } } } if (is_dynamic) { if (((fa.styles[maps] & 0xFF) >= 32 || fa.styles[maps] == 0) && (fa.dlightframe != r_framecount)) { // ist ersetzt durch temp2: unsigned temp[34*34]; int smax, tmax; smax = (fa.extents[0] >> 4) + 1; tmax = (fa.extents[1] >> 4) + 1; R_BuildLightMap(fa, temp2, smax); R_SetCacheState(fa); GL_Bind(gl_state.lightmap_textures + fa.lightmaptexturenum); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, fa.light_s, fa.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, temp2); fa.lightmapchain = gl_lms.lightmap_surfaces[fa.lightmaptexturenum]; gl_lms.lightmap_surfaces[fa.lightmaptexturenum] = fa; } else { fa.lightmapchain = gl_lms.lightmap_surfaces[0]; gl_lms.lightmap_surfaces[0] = fa; } } else { fa.lightmapchain = gl_lms.lightmap_surfaces[fa.lightmaptexturenum]; gl_lms.lightmap_surfaces[fa.lightmaptexturenum] = fa; } }
From source file:org.free.jake2.render.lwjgl.Surf.java
License:Open Source License
/** * GL_RenderLightmappedPoly// ww w. j a va 2 s.c o m * @param surf */ void GL_RenderLightmappedPoly(msurface_t surf) { // ersetzt goto boolean gotoDynamic = false; int map; for (map = 0; map < Defines.MAXLIGHTMAPS && (surf.styles[map] != (byte) 255); map++) { if (r_newrefdef.lightstyles[surf.styles[map] & 0xFF].white != surf.cached_light[map]) { gotoDynamic = true; break; } } // this is a hack from cwei if (map == 4) { map--; } // dynamic this frame or dynamic previously boolean is_dynamic = false; if (gotoDynamic || (surf.dlightframe == r_framecount)) { // label dynamic: if (gl_dynamic.value != 0) { if ((surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP)) == 0) { is_dynamic = true; } } } glpoly_t p; FloatBuffer texCoord = globalPolygonInterleavedBuf; image_t image = R_TextureAnimation(surf.texinfo); int lmtex = surf.lightmaptexturenum; if (is_dynamic) { // ist raus gezogen worden int[] temp = new int[128*128]; int smax, tmax; if (((surf.styles[map] & 0xFF) >= 32 || surf.styles[map] == 0) && (surf.dlightframe != r_framecount)) { smax = (surf.extents[0] >> 4) + 1; tmax = (surf.extents[1] >> 4) + 1; R_BuildLightMap(surf, temp, smax); R_SetCacheState(surf); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum); lmtex = surf.lightmaptexturenum; GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, temp); } else { smax = (surf.extents[0] >> 4) + 1; tmax = (surf.extents[1] >> 4) + 1; R_BuildLightMap(surf, temp, smax); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + 0); lmtex = 0; GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, temp); } c_brush_polys++; GL_MBind(GL_TEXTURE0, image.texnum); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + lmtex); // ========== // PGM if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) { float scroll; scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f)); if (scroll == 0.0f) { scroll = -64.0f; } for (p = surf.polys; p != null; p = p.chain) { p.beginScrolling(scroll); GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts); p.endScrolling(); } } else { for (p = surf.polys; p != null; p = p.chain) { GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts); } } // PGM // ========== } else { c_brush_polys++; GL_MBind(GL_TEXTURE0, image.texnum); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + lmtex); // ========== // PGM if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) { float scroll; scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f)); if (scroll == 0.0) { scroll = -64.0f; } for (p = surf.polys; p != null; p = p.chain) { p.beginScrolling(scroll); GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts); p.endScrolling(); } } else { // PGM // ========== for (p = surf.polys; p != null; p = p.chain) { GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts); } // ========== // PGM } // PGM // ========== } }
From source file:org.free.jake2.render.lwjgl.Surf.java
License:Open Source License
/** * LM_UploadBlock/* ww w . j a v a 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.llama.jmf.JMFVideoImage.java
License:Open Source License
/** * Update./*w w w.j a v a 2s.com*/ * * @param texture * Texture to update * @param syncToFrameRate * Wait till the frame is updated before updating the texture. * @return true if the texture was updated */ public boolean update(Texture texture, boolean syncToFrameRate) { if (!active) { return false; } if (syncToFrameRate) { synchronized (this) { while (lastupdated >= framecounter) { try { this.wait(); } catch (InterruptedException e) { } } } } if (lastupdated >= framecounter) { return false; } if ((lastupdated + 1) < framecounter) { log.info("missed frames: " + ((framecounter - lastupdated) + 1)); } if (data == null) { return false; } if (inittexture && (this.scalemethod > 0)) { inittexture = false; // clear current textures. TextureState state = DisplaySystem.getDisplaySystem().getRenderer().createTextureState(); state.setEnabled(true); state.apply(); log.info("rescaling texture"); if (scalemethod == SCALE_FIT) { float scale; if (this.videowidth > this.videoheight) { scale = videowidth * (1f / this.width); } else { scale = videoheight * (1f / this.height); } texture.setScale(new Vector3f(scale, scale, scale)); } if (scalemethod == SCALE_MAXIMIZE) { // texture.setScale(new Vector3f(1f,videowidth* (1f / // this.width), videoheight * (1f / this.height))); texture.setScale( new Vector3f(videowidth * (1f / this.width), videoheight * (1f / this.height), 1f)); } } synchronized (this) { // long d = System.currentTimeMillis(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId()); // TODO: use this.dataformat GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, videowidth, videoheight, pixelformat, dataformat, buffer); try { Util.checkGLError(); } catch (OpenGLException e) { log.info("Error rendering video to texture. No glTexSubImage2D/OpenGL 1.2 support?"); } lastupdated = framecounter; this.notifyAll(); } return false; }
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void texSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (FloatBuffer) pixels); else if (pixels instanceof DoubleBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (DoubleBuffer) pixels); else//from ww w . j a v a2 s . c om throw new GdxRuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL"); }
From source file:playn.java.JavaGL20.java
License:Apache License
@Override public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (FloatBuffer) pixels); else if (pixels instanceof DoubleBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (DoubleBuffer) pixels); else//from w ww .j av a 2 s .co m throw new RuntimeException( "Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, " + "ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL"); }