Java Code Examples for org.lwjgl.opengl.GL11#glBindTexture()

The following examples show how to use org.lwjgl.opengl.GL11#glBindTexture() . 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: ClientDynamicTexture.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
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 2
Source File: BuildingSiteRenderer.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
public final void renderSites(LandscapeRenderer renderer, List targets, float center_x, float center_y, float max_radius) {
	setupShadows();
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, green.getHandle());
	float radius_sqr = max_radius*max_radius;
	for (int i = 0; i < targets.size(); i++) {
		Target target = (Target)targets.get(i);
		float dx = target.getPositionX() - center_x;
		float dy = target.getPositionY() - center_y;
		float a = (dx*dx + dy*dy)/radius_sqr;
		if (dx == 0f && dy == 0f)
			GL11.glColor4f(1f, 1f, 1f, 1f);
		else
			GL11.glColor4f(0f, 1f, 0f, 1 - a*a);
		renderShadow(renderer, 2f, target.getPositionX(), target.getPositionY());
	}
	resetShadows();
}
 
Example 3
Source File: GUIImage.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
protected final void renderGeometry() {
	int width = getWidth();
	int height = getHeight();

	GL11.glEnd();
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getHandle());
	GL11.glBegin(GL11.GL_QUADS);

	GL11.glTexCoord2f(u1, v1);
	GL11.glVertex3f(0, 0, 0);
	GL11.glTexCoord2f(u2, v1);
	GL11.glVertex3f(width, 0, 0);
	GL11.glTexCoord2f(u2, v2);
	GL11.glVertex3f(width, height, 0);
	GL11.glTexCoord2f(u1, v2);
	GL11.glVertex3f(0, height, 0);

	GL11.glEnd();
	Skin.getSkin().bindTexture();
	GL11.glBegin(GL11.GL_QUADS);
}
 
Example 4
Source File: MixinGlStateManager.java    From VanillaFix with MIT License 6 votes vote down vote up
@Overwrite // overwrite for efficiency
public static void bindTexture(int texture) {
    if (texture != textureState[activeTextureUnit].textureName) {
        textureState[activeTextureUnit].textureName = texture;
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);

        if (activeTextureUnit == 0) {
            if (texture == TextureScaleInfo.textureId) {
                bound = true;
                scaleTextures();
            } else if (bound) {
                bound = false;
                unscaleTextures();
            }
        }
    }
}
 
Example 5
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the first row of the slider gradient texture and upload it as
 * a 1D texture to OpenGL if it hasn't already been done.
 */
public void initGradient() {
	if (gradientTexture == 0) {
		Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale());
		staticState.gradientTexture = GL11.glGenTextures();
		ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4);
		for (int i = 0; i < slider.getWidth(); ++i) {
			Color col = slider.getColor(i, 0);
			buff.put((byte) (255 * col.r));
			buff.put((byte) (255 * col.g));
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.a));
		}
		buff.flip();
		GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
		GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
		ContextCapabilities capabilities = GLContext.getCapabilities();
		if (capabilities.OpenGL30) {
			GL30.glGenerateMipmap(GL11.GL_TEXTURE_1D);
		} else if (capabilities.GL_EXT_framebuffer_object) {
			EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
		} else {
			GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
		}
	}
}
 
Example 6
Source File: Rendertarget.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
protected void bindTexture(TextureHandle texture) {
	if(lastTexture != texture) {
		int id = 0;
		if (texture != null) {
			id = texture.getInternalId();
		}
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
		lastTexture = texture;
	}
}
 
Example 8
Source File: TextureUtils.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
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 9
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 10
Source File: LwjglTextureUtils.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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 11
Source File: LandscapeRenderer.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
final void bindMap(int x, int y) {
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, colormaps[y][x].getHandle());
}
 
Example 12
Source File: Graphics.java    From AnyaBasic with MIT License 4 votes vote down vote up
public void drawSpriteOnLine( int x1, int y1,
                       int x2, int y2,
                       int width, int type )
{


    SpriteGL sprite  = glowImages.getSprite(type % glowImages.getNumImages());

    // Only change active texture when there is a need
    // Speeds up the rendering by batching textures

    if ( sprite.textureID != currentTexture )
    {
        GL11.glBindTexture( GL11.GL_TEXTURE_2D, sprite.textureID );
        currentTexture = sprite.textureID;
    }

    float u1 = sprite.u1;
    float v1 = sprite.v1;
    float u2 = sprite.u2;
    float v2 = sprite.v2;
    float uh = (u1 + u2)/2.0f;

    float nx,ny;
    nx = -( y2-y1 );
    ny =  ( x2-x1 );

    float leng;
    leng = (float)Math.sqrt( nx * nx + ny * ny );
    nx = nx / leng;
    ny = ny / leng;

    nx *= width / 2.0;
    ny *= width / 2.0;

    float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4;

    lx1 = x2 + nx;
    ly1 = y2 + ny;
    lx2 = x2 - nx;
    ly2 = y2 - ny;
    lx3 = x1 - nx;
    ly3 = y1 - ny;
    lx4 = x1 + nx;
    ly4 = y1 + ny;

    // MAIN
    GL11.glBegin( GL11.GL_QUADS );
    GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx1, ly1, 0.0f );
    GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx2, ly2, 0.0f );
    GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx3, ly3, 0.0f );
    GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx4, ly4, 0.0f );
    GL11.glEnd();

    //RIGHT
    float lx5, ly5, lx6, ly6, vx, vy;
    vx = ( x2-x1 );
    vy = ( y2-y1 );
    leng = (float)Math.sqrt( vx * vx + vy * vy );
    vx = vx / leng;
    vy = vy / leng;
    vx *= width / 2.0;
    vy *= width / 2.0;

    lx5 = lx1 + vx;
    ly5 = ly1 + vy;
    lx6 = lx2 + vx;
    ly6 = ly2 + vy;

    GL11.glBegin( GL11.GL_QUADS );
    GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx1, ly1,0.0f );
    GL11.glTexCoord2f( u2, v1 ); GL11.glVertex3f( lx5, ly5,0.0f );
    GL11.glTexCoord2f( u2, v2 ); GL11.glVertex3f( lx6, ly6,0.0f );
    GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx2, ly2,0.0f );
    GL11.glEnd();

    // LEFT
    lx5 = lx4 - vx;
    ly5 = ly4 - vy;
    lx6 = lx3 - vx;
    ly6 = ly3 - vy;

    GL11.glBegin( GL11.GL_QUADS );
    GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx4, ly4, 0.0f );
    GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx3, ly3 ,0.0f );
    GL11.glTexCoord2f( u2, v2 ); GL11.glVertex3f( lx6, ly6, 0.0f );
    GL11.glTexCoord2f( u2, v1 ); GL11.glVertex3f( lx5, ly5, 0.0f );
    GL11.glEnd();

}
 
Example 13
Source File: TrueTypeFont.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public void drawString(float x, float y, String whatchars, int startIndex, int endIndex, float scaleX, float scaleY, int format, float... rgba) {
	if(rgba.length == 0) rgba = new float[]{1f,1f,1f,1f};
	GL11.glPushMatrix();
	GL11.glScalef (scaleX, scaleY, 1.0f);

	FloatObject floatObject = null;
	int charCurrent;


	float totalwidth = 0;
	int i = startIndex, d, c;
	float startY = 0;



	switch (format) {
		case ALIGN_RIGHT: {
			d = -1;
			c = correctR;

			while (i < endIndex) {
				if (whatchars.charAt(i) == '\n') startY -= fontHeight;
				i++;
			}
			break;
		}
		case ALIGN_CENTER: {
			for (int l = startIndex; l <= endIndex; l++) {
				charCurrent = whatchars.charAt(l);
				if (charCurrent == '\n') break;
				if (charCurrent < 256) {
					floatObject = charArray[charCurrent];
				} else {
					floatObject = (FloatObject)customChars.get( new Character( (char) charCurrent ) );
				}
				totalwidth += floatObject.width-correctL;
			}
			totalwidth /= -2;
		}
		case ALIGN_LEFT:
		default: {
			d = 1;
			c = correctL;
			break;
		}

	}
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, fontTextureID);
	Tessellator t = Tessellator.instance;
	t.startDrawingQuads();
//	GL11.glBegin(GL11.GL_QUADS);
	if(rgba.length == 4) t.setColorRGBA_F(rgba[0], rgba[1], rgba[2], rgba[3]);
	while (i >= startIndex && i <= endIndex) {

		charCurrent = whatchars.charAt(i);
		if (charCurrent < 256) {
			floatObject = charArray[charCurrent];
		} else {
			floatObject = (FloatObject)customChars.get( new Character( (char) charCurrent ) );
		}

		if( floatObject != null ) {
			if (d < 0) totalwidth += (floatObject.width-c) * d;
				if (charCurrent == '\n') {
					startY -= fontHeight * d;
					totalwidth = 0;
					if (format == ALIGN_CENTER) {
						for (int l = i+1; l <= endIndex; l++) {
							charCurrent = whatchars.charAt(l);
							if (charCurrent == '\n') break;
							if (charCurrent < 256) {
								floatObject = charArray[charCurrent];
							} else {
								floatObject = (FloatObject)customChars.get( new Character( (char) charCurrent ) );
							}
							totalwidth += floatObject.width-correctL;
						}
						totalwidth /= -2;
					}
					//if center get next lines total width/2;
				}
				else {
					drawQuad((totalwidth + floatObject.width) + x/scaleX,
							 startY + y/scaleY,
							 totalwidth + x/scaleX,
							 (startY + floatObject.height) + y/scaleY,
						floatObject.storedX + floatObject.width,
						floatObject.storedY + floatObject.height,
						floatObject.storedX,
						floatObject.storedY);
					if (d > 0) totalwidth += (floatObject.width-c) * d ;
				}
				i += d;

		}
	}
	t.draw();
//	GL11.glEnd();

	GL11.glPopMatrix();
}
 
Example 14
Source File: RenderPortal.java    From LookingGlass with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void doRender(Entity entity, double d, double d1, double d2, float f, float f1) {
	if (!(entity instanceof EntityPortal)) return;
	EntityPortal portal = (EntityPortal) entity;
	IWorldView activeview = portal.getActiveView();
	if (activeview == null) return;

	int texture = activeview.getTexture();
	if (texture == 0) return;

	int width = 2;
	int height = 3;
	double left = -width / 2.;
	double top = 0;

	activeview.markDirty();
	GL11.glDisable(GL11.GL_ALPHA_TEST);
	GL11.glDisable(GL11.GL_LIGHTING);

	GL11.glPushMatrix();
	GL11.glTranslatef((float) d, (float) d1, (float) d2);

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
	Tessellator tessellator = Tessellator.instance;
	tessellator.setColorRGBA_F(1, 1, 1, 1);
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV(left, top, 0.0D, 0.0D, 0.0D); //inc=bl out; inc=bl down
	tessellator.addVertexWithUV(width + left, top, 0.0D, 1.0D, 0.0D); //dc=br out; inc=br down
	tessellator.addVertexWithUV(width + left, height + top, 0.0D, 1.0D, 1.0D); //dec=tr out; dec=tr up
	tessellator.addVertexWithUV(left, height + top, 0.0D, 0.0D, 1.0D); //inc=lt out; dec=tl up
	tessellator.draw();
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
	//XXX: Make the back of the portals a little nicer
	tessellator.setColorRGBA_F(0, 0, 1, 1);
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV(left, height + top, 0.0D, 0.0D, 1.0D);
	tessellator.addVertexWithUV(width + left, height + top, 0.0D, 1.0D, 1.0D);
	tessellator.addVertexWithUV(width + left, top, 0.0D, 1.0D, 0.0D);
	tessellator.addVertexWithUV(left, top, 0.0D, 0.0D, 0.0D);
	tessellator.draw();
	GL11.glPopMatrix();

	GL11.glEnable(GL11.GL_LIGHTING);
	GL11.glEnable(GL11.GL_ALPHA_TEST);
}
 
Example 15
Source File: Texture.java    From mapwriter with MIT License 4 votes vote down vote up
public void bind() {
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.id);
}
 
Example 16
Source File: GTexture.java    From ldparteditor with MIT License 4 votes vote down vote up
public void bind(boolean drawSolidMaterials, boolean normalSwitch, boolean lightOn, OpenGLRenderer20 renderer, int useCubeMap) {

        int ID = -1;
        int ID_glossmap = -1;
        int ID_cubemap = -1;
        int ID_cubemap_matte = -1;
        int ID_cubemap_metal = -1;
        boolean disposed = true;

        if (OpenGlDisposed.containsKey(renderer)) {
            disposed = OpenGlDisposed.get(renderer);
            ID = OpenGlID.get(renderer);
            ID_glossmap = OpenGlID_glossmap.get(renderer);
            ID_cubemap = OpenGlID_cubemap.get(renderer);
            ID_cubemap_matte = OpenGlID_cubemapMatte.get(renderer);
            ID_cubemap_metal = OpenGlID_cubemapMetal.get(renderer);
        } else {
            OpenGlDisposed.put(renderer, true);
        }

        if (disposed) {

            DatFile df = renderer.getC3D().getLockableDatFileReference();

            ID = loadPNGTexture(texture, GL13.GL_TEXTURE0, df);
            if (glossy)
                ID_glossmap = loadPNGTexture(glossmap, GL13.GL_TEXTURE1, df);
            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    ID_cubemap = loadPNGTexture("cmap.png", GL13.GL_TEXTURE2, df ); //$NON-NLS-1$
                    break;
                case 2:
                    ID_cubemap_matte = loadPNGTexture("matte_metal.png", GL13.GL_TEXTURE3, df); //$NON-NLS-1$
                    break;
                case 3:
                    ID_cubemap_metal = loadPNGTexture("metal.png", GL13.GL_TEXTURE4, df); //$NON-NLS-1$
                    break;
                }
            }
            OpenGlDisposed.put(renderer, false);
            renderer.registerTexture(this);
            OpenGlID.put(renderer, ID);
            OpenGlID_glossmap.put(renderer, ID_glossmap);
            OpenGlID_cubemap.put(renderer, ID_cubemap);
            OpenGlID_cubemapMatte.put(renderer, ID_cubemap_matte);
            OpenGlID_cubemapMetal.put(renderer, ID_cubemap_metal);
        } else if (ID != -1) {
            accessTime = System.currentTimeMillis();
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + 0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID);
            GL20.glUniform1f(renderer.getAlphaSwitchLoc(), drawSolidMaterials ? 1f : 0f); // Draw transparent
            GL20.glUniform1f(renderer.getNormalSwitchLoc(), normalSwitch ? 1f : 0f); // Draw transparent
            GL20.glUniform1i(renderer.getBaseImageLoc(), 0); // Texture unit 0 is for base images.
            GL20.glUniform1f(renderer.getNoTextureSwitch(), 0f);
            GL20.glUniform1f(renderer.getNoLightSwitch(), lightOn ? 0f : 1f);
            GL20.glUniform1f(renderer.getCubeMapSwitch(), useCubeMap);

            if (glossy) {
                GL13.glActiveTexture(GL13.GL_TEXTURE0 + 2);
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_glossmap);
                GL20.glUniform1i(renderer.getGlossMapLoc(), 2); // Texture unit 2 is for gloss maps.
                GL20.glUniform1f(renderer.getNoGlossMapSwitch(), 0f);
            } else {
                GL20.glUniform1f(renderer.getNoGlossMapSwitch(), 1f);
            }
            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 4);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap);
                    GL20.glUniform1i(renderer.getCubeMapLoc(), 4); // Texture unit 4 is for cube maps.
                    break;
                case 2:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 8);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_matte);
                    GL20.glUniform1i(renderer.getCubeMapMatteLoc(), 8); // Texture unit 8 is for cube maps.
                    break;
                case 3:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 16);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_metal);
                    GL20.glUniform1i(renderer.getCubeMapMetalLoc(), 16); // Texture unit 16 is for cube maps.
                    break;
                }
            }
        }
    }
 
Example 17
Source File: StructureBlend.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final void bindStructure() {
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, structure_map.getHandle());
}
 
Example 18
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
public void render(Context context, int x, int y, int w, int h) {
	if (quadShader == null) {
		quadShader = new GenericShader();
	}
	float pixelRatio = LWJGUI.getThreadWindow().getPixelRatio();
	x *= pixelRatio;
	y *= pixelRatio;
	GL11.glViewport(x, y,(int) (w*pixelRatio),(int) (h*pixelRatio));
	quadShader.bind();
	quadShader.projectOrtho(0, 0, w, h);
	
	if (quadDirty) {
		quadDirty = false;
		if (quad != null) {
			quad.cleanup();
		}
		quad = new TexturedQuad(0, 0, w, h, texId);
	}
	if ( context.isCoreOpenGL() ) {
		if ( quad != null ) {
			quad.render();
		}
	} else {

		GL13.glActiveTexture(GL13.GL_TEXTURE0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
		
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2f(0, 0);

			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 0);
			GL11.glVertex2f(w, 0);

			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 1);
			GL11.glVertex2f(w, h);

			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 1);
			GL11.glVertex2f(0, h);
		GL11.glEnd();
	}
}
 
Example 19
Source File: BlendInfo.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
protected final void bindAlpha() {
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, alpha_map.getHandle());
}
 
Example 20
Source File: WaterRenderer.java    From LowPolyWater with The Unlicense 2 votes vote down vote up
/**
 * Binds a texture to a given unit.
 * 
 * @param textureId
 *            - The ID of the texture object.
 * @param textureUnit
 *            - The index of the texture unit.
 */
private void bindTextureToUnit(int textureId, int textureUnit) {
	GL13.glActiveTexture(GL13.GL_TEXTURE0 + textureUnit);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
}