Java Code Examples for org.lwjgl.opengl.GL13#glActiveTexture()

The following examples show how to use org.lwjgl.opengl.GL13#glActiveTexture() . 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: PaletteSwapper.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static ShaderArgs setup(FightUnit u) {
	Unit unit = u.getUnit();
	ShaderArgs args = new ShaderArgs();
	if(unit.getTheClass().name.equals("Lord")) return args;
	String c = unit.functionalClassName();
	
	Texture t = palettes.get(c);
	if(t == null) return args;
	if(lookup.get(c) == null) return args;
	int offset = lookup.get(c).indexOf(unit.name);
	if(offset < 0) return args;
	args.programName = "paletteSwap";
	args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()};
	GL13.glActiveTexture(GL13.GL_TEXTURE8);
	t.bind();
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	return args;
}
 
Example 2
Source File: TexturedQuad.java    From LWJGUI with MIT License 6 votes vote down vote up
public void render() {
	GL11.glDisable(GL11.GL_CULL_FACE);
	
	// bind stuff
	GL30.glBindVertexArray(vaoId);
	if ( texId > -1 ) {
		GL13.glActiveTexture(GL13.GL_TEXTURE0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
	}

	// draw it!
	glBindVertexArray(vaoId);
	glDrawArrays(GL_TRIANGLES, 0, 6);

	// unbind things
	GL30.glBindVertexArray(0);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}
 
Example 3
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Restore the old OpenGL state that's backed up in {@code state}.
 * @param state the old state to restore
 */
private void restoreRenderState(RenderState state) {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPopMatrix();
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPopMatrix();
	GL11.glEnable(GL11.GL_BLEND);
	GL20.glUseProgram(state.oldProgram);
	GL13.glActiveTexture(state.texUnit);
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, state.oldArrayBuffer);
	if (!state.depthWriteEnabled)
		GL11.glDepthMask(false);
	if (!state.depthEnabled)
		GL11.glDisable(GL11.GL_DEPTH_TEST);
	if (state.texEnabled)
		GL11.glEnable(GL11.GL_TEXTURE_2D);
	if (state.smoothedPoly)
		GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
	if (!state.blendEnabled)
		GL11.glDisable(GL11.GL_BLEND);
}
 
Example 4
Source File: PaletteSwapper.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Setup.
 *
 * @param u the u
 * @return the shader args
 */
public static ShaderArgs setup(FightUnit u) {
	Unit unit = u.getUnit();
	ShaderArgs args = new ShaderArgs();
	if(unit.getTheClass().name.equals("Lord")) return args;
	String c = unit.functionalClassName();
	
	Texture t = palettes.get(c);
	if(t == null) return args;
	if(lookup.get(c) == null) return args;
	int offset = lookup.get(c).indexOf(unit.name);
	if(offset < 0) return args;
	args.programName = "paletteSwap";
	args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()};
	GL13.glActiveTexture(GL13.GL_TEXTURE8);
	t.bind();
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	return args;
}
 
Example 5
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Restore the old OpenGL state that's backed up in {@code state}.
 * @param state the old state to restore
 */
private void restoreRenderState(RenderState state) {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPopMatrix();
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPopMatrix();
	GL11.glEnable(GL11.GL_BLEND);
	GL20.glUseProgram(state.oldProgram);
	GL13.glActiveTexture(state.texUnit);
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, state.oldArrayBuffer);
	if (!state.depthWriteEnabled)
		GL11.glDepthMask(false);
	if (!state.depthEnabled)
		GL11.glDisable(GL11.GL_DEPTH_TEST);
	if (state.texEnabled)
		GL11.glEnable(GL11.GL_TEXTURE_2D);
	if (state.smoothedPoly)
		GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
	if (!state.blendEnabled)
		GL11.glDisable(GL11.GL_BLEND);
}
 
Example 6
Source File: PaletteSwapper.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Setup.
 *
 * @param u the u
 * @return the shader args
 */
public static ShaderArgs setup(Unit u) {
	ShaderArgs args = new ShaderArgs();
	int offset = u.getPartyColor().equals(Party.TEAM_BLUE) ? 0 : 1;
	if(offset == 0) return args;
	
	Texture t = palettes.get("overworld");
	args.programName = "paletteSwap";
	args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()};
	GL13.glActiveTexture(GL13.GL_TEXTURE8);
	t.bind();
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	return args;
}
 
Example 7
Source File: PaletteSwapper.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public static ShaderArgs setup(Unit u) {
	ShaderArgs args = new ShaderArgs();
	int offset = u.getPartyColor().equals(Party.TEAM_BLUE) ? 0 : 1;
	if(offset == 0) return args;
	
	Texture t = palettes.get("overworld");
	args.programName = "paletteSwap";
	args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()};
	GL13.glActiveTexture(GL13.GL_TEXTURE8);
	t.bind();
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	return args;
}
 
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: Texture.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
public void bindToUnit(int unit) {
	GL13.glActiveTexture(GL13.GL_TEXTURE0 + unit);
	GL11.glBindTexture(type, textureId);
}
 
Example 10
Source File: BlurPane.java    From LWJGUI with MIT License 4 votes vote down vote up
@Override
public void render(Context context, int x, int y, int w, int h) {
	if ( !isVisible() )
		return;
	
	if ( this.quad == null || quadDirty ) {
		if ( this.quad != null ) {
			this.quad.cleanup();
		}
		quad = new TexturedQuad(0, 0, w, h, source.getTexId());
	}
	
	GL11.glViewport(x, y, w, h);
	this.quadDirty = false;
	quadShader.bind();
	quadShader.projectOrtho(0, h, w, -h);
	
	// bind stuff
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId());
	
	if ( internalBackground instanceof BackgroundSolid ) {
		BackgroundSolid bg = (BackgroundSolid)internalBackground;
		GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uColor"),
				bg.getColor().getRed()/255f-0.5f,
				bg.getColor().getGreen()/255f-0.5f,
				bg.getColor().getBlue()/255f-0.5f,
				bg.getColor().getAlpha()/255f);
	}
	GL20.glUniform1f(GL20.glGetUniformLocation(quadShader.getProgram(), "uBlurSize"), blurRadius);
	GL20.glUniform2f(GL20.glGetUniformLocation(quadShader.getProgram(), "uTexelSize"), 1.0f/(float)w, 1.0f/(float)h);
	GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uCornerRadii"), (float)Math.max(BlurPane.this.getBorderRadii()[0], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[1], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[2], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[3], 0.1));
	
	
	// Draw quad
	if ( context.isCoreOpenGL() ) {
		if ( quad != null ) {
			quad.render();
		}
	} else {

		GL13.glActiveTexture(GL13.GL_TEXTURE0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId());
		
		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 11
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 4 votes vote down vote up
private void loopCycle() {
    // Logic
    while(Keyboard.next()) {
        // Only listen to events where the key was pressed (down event)
        if (!Keyboard.getEventKeyState()) continue;
         
        // Switch textures depending on the key released
        switch (Keyboard.getEventKey()) {
        case Keyboard.KEY_1:
            textureSelector = 0;
            break;
        case Keyboard.KEY_2:
            textureSelector = 1;
            break;
        }
    }
     
    // Render
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
     
    GL20.glUseProgram(pId);
     
    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texIds[textureSelector]);
     
    // Bind to the VAO that has all the information about the vertices
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
     
    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
     
    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
     
    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
     
    GL20.glUseProgram(0);
     
    this.exitOnGLError("loopCycle");
}
 
Example 12
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 4 votes vote down vote up
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 13
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 14
Source File: GTexture.java    From ldparteditor with MIT License 4 votes vote down vote up
public void bindGL33(OpenGLRenderer renderer, GLShader shader) {

        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 (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.glUniform1i(shader.getUniformLocation("ldpePngSampler"), 0); // Texture unit 0 is for base images. //$NON-NLS-1$

            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 4);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap);
                    GL20.glUniform1i(shader.getUniformLocation("cubeMap"), 4); // Texture unit 4 is for cube maps. //$NON-NLS-1$
                    break;
                case 2:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 8);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_matte);
                    GL20.glUniform1i(shader.getUniformLocation("cubeMapMatte"), 8); // Texture unit 8 is for cube maps. //$NON-NLS-1$
                    break;
                case 3:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 16);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_metal);
                    GL20.glUniform1i(shader.getUniformLocation("cubeMapMetal"), 16); // Texture unit 16 is for cube maps. //$NON-NLS-1$
                    break;
                }
            }
        }
    }
 
Example 15
Source File: GLState.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final static void activeTexture(int texture) {
	if (GLContext.getCapabilities().OpenGL13)
		GL13.glActiveTexture(texture);
	else
		ARBMultitexture.glActiveTextureARB(texture);
}
 
Example 16
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 17
Source File: GenericShader.java    From LWJGUI with MIT License 4 votes vote down vote up
public void bind() {
	GL20.glUseProgram(id);

	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
}
 
Example 18
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);
}