org.lwjgl.opengl.GL13 Java Examples

The following examples show how to use org.lwjgl.opengl.GL13. 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 Project: LWJGUI   Author: orange451   File: TexturedQuad.java    License: 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 #2
Source Project: OpenGL-Animation   Author: TheThinMatrix   File: DisplayManager.java    License: The Unlicense 6 votes vote down vote up
public static void createDisplay() {
	try {
		Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
		ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
		Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs);
		Display.setTitle(TITLE);
		Display.setInitialBackground(1, 1, 1);
		GL11.glEnable(GL13.GL_MULTISAMPLE);
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.err.println("Couldn't create display!");
		System.exit(-1);
	}
	GL11.glViewport(0, 0, WIDTH, HEIGHT);
	lastFrameTime = getCurrentTime();
}
 
Example #3
Source Project: opsu-dance   Author: yugecin   File: CurveRenderState.java    License: 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 Project: FEMultiPlayer-V2   Author: eliatlarge   File: PaletteSwapper.java    License: 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 Project: tribaltrouble   Author: sunenielsen   File: LandscapeRenderer.java    License: GNU General Public License v2.0 6 votes vote down vote up
private final void setupLandscape() {
	current_map_x = -1;
	current_map_y = -1;
	GL11.glEnable(GL11.GL_TEXTURE_GEN_S);
	GL11.glEnable(GL11.GL_TEXTURE_GEN_T);
	GLStateStack.switchState(GLState.VERTEX_ARRAY);
	if (Globals.draw_detail) {
		GLState.activeTexture(GL13.GL_TEXTURE1);
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		bindDetail();
		GL11.glEnable(GL11.GL_TEXTURE_GEN_S);
		GL11.glEnable(GL11.GL_TEXTURE_GEN_T);
		GLUtils.setupTexGen(Globals.LANDSCAPE_DETAIL_REPEAT_RATE, Globals.LANDSCAPE_DETAIL_REPEAT_RATE, 0, 0);
		GLState.activeTexture(GL13.GL_TEXTURE0);
	}
	GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ZERO);
	GL11.glEnable(GL11.GL_BLEND);
}
 
Example #6
Source Project: opsu   Author: itdelatrisu   File: LegacyCurveRenderState.java    License: 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 #7
Source Project: FEMultiplayer   Author: chudooder   File: PaletteSwapper.java    License: 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 #8
Source Project: LowPolyWater   Author: TheThinMatrix   File: OpenGlUtils.java    License: The Unlicense 5 votes vote down vote up
public static void antialias(boolean enable) {
	if (enable && !antialiasing) {
		GL11.glEnable(GL13.GL_MULTISAMPLE);
		antialiasing = true;
	} else if (!enable && antialiasing) {
		GL11.glDisable(GL13.GL_MULTISAMPLE);
		antialiasing = false;
	}
}
 
Example #9
Source Project: OpenGL-Animation   Author: TheThinMatrix   File: OpenGlUtils.java    License: The Unlicense 5 votes vote down vote up
public static void antialias(boolean enable) {
	if (enable && !antialiasing) {
		GL11.glEnable(GL13.GL_MULTISAMPLE);
		antialiasing = true;
	} else if (!enable && antialiasing) {
		GL11.glDisable(GL13.GL_MULTISAMPLE);
		antialiasing = false;
	}
}
 
Example #10
Source Project: OpenGL-Animation   Author: TheThinMatrix   File: TextureUtils.java    License: 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 #11
Source Project: opsu-dance   Author: yugecin   File: CurveRenderState.java    License: 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 #12
Source Project: CodeChickenLib   Author: TheCBProject   File: VBORenderType.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setupRenderState() {
    super.setupRenderState();
    states.forEach(RenderState::setupRenderState);
    RenderSystem.pushMatrix();
    matrix.glApply();
    if (hasLightMap) {
        RenderSystem.glMultiTexCoord2f(GL13.GL_TEXTURE2, packedLight & 0xFFFF, packedLight >>> 16);
    }
}
 
Example #13
Source Project: FEMultiPlayer-V2   Author: eliatlarge   File: PaletteSwapper.java    License: 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 #14
Source Project: Visage   Author: unascribed-archive   File: Errors.java    License: MIT License 5 votes vote down vote up
private static void buildMapping() {
	if (mapping != null) return;
	Multimap<Integer, String> map = HashMultimap.create();
	List<Class<?>> classes = ImmutableList.of(
			GL11.class, GL12.class, GL13.class, GL14.class, GL15.class,
			GL20.class, GL21.class, GL30.class, GL31.class, GL32.class,
			GL33.class, GL40.class, GL41.class, GL42.class, GL43.class,
			GL44.class, GL45.class, GLFW.class
			);
	for (Class<?> clazz : classes) {
		for (Field f : clazz.getDeclaredFields()) {
			if (f.getName().toUpperCase(Locale.ROOT).equals(f.getName()) &&
					f.getType() == int.class && Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())) {
				List<String> li = Splitter.on('_').splitToList(f.getName());
				li = li.subList(1, li.size());
				String clean =
					Joiner.on(' ').join(
						li.stream()
							.map(Errors::toTitleCase)
							.iterator());
				try {
					map.put(f.getInt(null), clean);
				} catch (Throwable t) {
					t.printStackTrace();
				}
			}
		}
	}
	mapping = map;
}
 
Example #15
Source Project: tribaltrouble   Author: sunenielsen   File: StructureBlend.java    License: GNU General Public License v2.0 5 votes vote down vote up
public final void setup() {
	GLState.activeTexture(GL13.GL_TEXTURE1);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	bindAlpha();
	GLState.activeTexture(GL13.GL_TEXTURE0);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	bindStructure();
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
 
Example #16
Source Project: tribaltrouble   Author: sunenielsen   File: BlendLighting.java    License: GNU General Public License v2.0 5 votes vote down vote up
public final void setup() {
	GLState.activeTexture(GL13.GL_TEXTURE1);
	GL11.glColor3f(r, b, g);
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	bindAlpha();
	GLState.activeTexture(GL13.GL_TEXTURE0);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE);
}
 
Example #17
Source Project: tribaltrouble   Author: sunenielsen   File: Renderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public final static void initGL() {
		VBO.releaseAll();
		GL11.glFrontFace(GL11.GL_CCW);
		GL11.glCullFace(GL11.GL_BACK);
		GL11.glEnable(GL11.GL_CULL_FACE); 
		GL11.glPixelStorei(GL11.GL_PACK_ROW_LENGTH, 0);
		GL11.glPixelStorei(GL11.GL_PACK_SKIP_PIXELS, 0);
		GL11.glPixelStorei(GL11.GL_PACK_SKIP_ROWS, 0);
		GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
		GL11.glPixelStorei(GL11.GL_PACK_SWAP_BYTES, 0);

		GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0);
		GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, 0);
		GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, 0);
		GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
		GL11.glPixelStorei(GL11.GL_UNPACK_SWAP_BYTES, 0);
		GL11.glEnable(GL11.GL_DEPTH_TEST);
		GL11.glDepthFunc(GL11.GL_LEQUAL);
		GL11.glShadeModel(GL11.GL_SMOOTH);
//		GL11.glAlphaFunc(GL11.GL_GREATER, Globals.ALPHA_CUTOFF);
		// Setup landscape texture coordinate gen
		GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
		GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
		GLState.activeTexture(GL13.GL_TEXTURE1);
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_DECAL);
		GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
		GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
		GLState.activeTexture(GL13.GL_TEXTURE0);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);

		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

		GL11.glPointSize(7.0f);
		clearScreen();
		GL11.glClearDepth(1.0);
	}
 
Example #18
Source Project: tribaltrouble   Author: sunenielsen   File: LandscapeRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final static void disableLandscape() {
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	if (Globals.draw_detail) {
		GLState.activeTexture(GL13.GL_TEXTURE1);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
		GL11.glDisable(GL11.GL_TEXTURE_2D);
		GLState.activeTexture(GL13.GL_TEXTURE0);
	}
	GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
	GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
}
 
Example #19
Source Project: tribaltrouble   Author: sunenielsen   File: Sprite.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final void doSetup(FloatBuffer color, int tex_index, boolean respond, boolean modulate_color) {
	int gl_flags = setupBasic();
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textures[tex_index][TEXTURE_NORMAL].getHandle());
	if (modulate_color) {
		GL11.glAlphaFunc(GL11.GL_GREATER, 0f);
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
	} else if (Globals.draw_light && lighted) {
		gl_flags = gl_flags | GLState.NORMAL_ARRAY;
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
		GL11.glEnable(GL11.GL_LIGHTING);
		GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, color);
	}
	GL11.glColor4f(color.get(0), color.get(1), color.get(2), color.get(3));
	if (!modulate_color && (hasTeamDecal() || respond)) {
		gl_flags = gl_flags | GLState.TEXCOORD1_ARRAY;
		setupTeamDecal();
		if (respond) {
			GL11.glBindTexture(GL11.GL_TEXTURE_2D, respond_texture.getHandle());
		} else {
			GL11.glBindTexture(GL11.GL_TEXTURE_2D, textures[tex_index][TEXTURE_TEAM].getHandle());
		}
		GLState.clientActiveTexture(GL13.GL_TEXTURE1);
		texcoords.texCoordPointer(2, 0, 0);
		GLState.clientActiveTexture(GL13.GL_TEXTURE0);
	}
	GLStateStack.switchState(gl_flags);
}
 
Example #20
Source Project: tribaltrouble   Author: sunenielsen   File: Texture.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static int determineMipMapSize(int mipmap, int internal_format, int width, int height) {
	boolean compressed = false;
	if (Settings.getSettings().useTextureCompression()) {
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap, GL13.GL_TEXTURE_COMPRESSED, size_buffer);
		compressed = size_buffer.get(0) == GL11.GL_TRUE;
	}
	if (compressed) {
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap, GL13.GL_TEXTURE_COMPRESSED_IMAGE_SIZE, size_buffer);
		return size_buffer.get(0);
	} else {
		switch (internal_format) {
			case GL13.GL_COMPRESSED_RGB:
			case GL11.GL_RGB:
				return width*height*3;
			case GL13.GL_COMPRESSED_RGBA:
			case GL11.GL_RGBA:
				return width*height*4;
			case GL11.GL_LUMINANCE:
			case GL11.GL_ALPHA8:
			case GL11.GL_ALPHA:
			case GL13.GL_COMPRESSED_LUMINANCE:
			case GL13.GL_COMPRESSED_ALPHA:
				return width*height;
			default:
				throw new RuntimeException("0x" + Integer.toHexString(internal_format));
		}
	}
}
 
Example #21
Source Project: tribaltrouble   Author: sunenielsen   File: Sky.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final void setupSky() {
	float time = LocalEventQueue.getQueue().getTime();
	float speed_scale = 0.01f;
	float outer_dx = SKYDOME_SPEED_OUTER[0] * time*speed_scale;
	float outer_dy = SKYDOME_SPEED_OUTER[1] * time*speed_scale;
	float inner_dx = SKYDOME_SPEED_INNER[0] * time*speed_scale;
	float inner_dy = SKYDOME_SPEED_INNER[1] * time*speed_scale;
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, clouds[GeneratorClouds.INNER].getHandle());
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_BLEND);
	GL11.glTexEnv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, color);
	GL11.glMatrixMode(GL11.GL_TEXTURE);
	GL11.glTranslatef(outer_dx, outer_dy, 0);
	GLState.activeTexture(GL13.GL_TEXTURE1);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, clouds[GeneratorClouds.OUTER].getHandle());
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glTranslatef(inner_dx, inner_dy, 0);
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_BLEND);
	GL11.glTexEnv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, color);
	

	GLStateStack.switchState(GLState.VERTEX_ARRAY | GLState.COLOR_ARRAY | GLState.TEXCOORD0_ARRAY | GLState.TEXCOORD1_ARRAY);
	sky_vertices.vertexPointer(3, 0, 0);
	sky_tex0.texCoordPointer(2, 0, 0);
	sky_colors.colorPointer(3, 0, 0);
	GLState.clientActiveTexture(GL13.GL_TEXTURE1);
	sky_tex1.texCoordPointer(2, 0, 0);
	GLState.clientActiveTexture(GL13.GL_TEXTURE0);
}
 
Example #22
Source Project: tribaltrouble   Author: sunenielsen   File: Sky.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final void resetSky() {
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glLoadIdentity();
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_DECAL);
	GLState.activeTexture(GL13.GL_TEXTURE0);
	GL11.glLoadIdentity();
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
 
Example #23
Source Project: tribaltrouble   Author: sunenielsen   File: Sky.java    License: GNU General Public License v2.0 5 votes vote down vote up
public final void renderSeaBottom() {
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glColor3f(Globals.SEA_BOTTOM_COLOR[terrain_type][0], Globals.SEA_BOTTOM_COLOR[terrain_type][1], Globals.SEA_BOTTOM_COLOR[terrain_type][2]);

	GLStateStack.switchState(GLState.VERTEX_ARRAY);
	if (Globals.draw_detail) {
		GLState.activeTexture(GL13.GL_TEXTURE1);
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		landscape_renderer.bindDetail();
		GL11.glMatrixMode(GL11.GL_TEXTURE);
		GL11.glLoadIdentity();
		GL11.glEnable(GL11.GL_TEXTURE_GEN_S);
		GL11.glEnable(GL11.GL_TEXTURE_GEN_T);
		GLUtils.setupTexGen(1, 1, 0, 0);
		GL11.glScalef(Globals.LANDSCAPE_DETAIL_REPEAT_RATE, Globals.LANDSCAPE_DETAIL_REPEAT_RATE, 1);
	}

	bottom_vertices.vertexPointer(3, 0, 0);
	water_indices.drawRangeElements(GL11.GL_TRIANGLES, 0, bottom_vertices.capacity()/3, water_indices.capacity(), 0);

	if (Globals.draw_detail) {
		GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
		GL11.glLoadIdentity();
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glDisable(GL11.GL_TEXTURE_2D);
		GLState.activeTexture(GL13.GL_TEXTURE0);
	}

	GL11.glEnable(GL11.GL_TEXTURE_2D);
}
 
Example #24
Source Project: tribaltrouble   Author: sunenielsen   File: GLState.java    License: GNU General Public License v2.0 5 votes vote down vote up
public final void switchState(int client_flags) {
		boolean target_vertex_array = (client_flags & VERTEX_ARRAY) != 0;
//		assert GLUtils.getGLInteger(GL13.GL_CLIENT_ACTIVE_TEXTURE) == GL13.GL_TEXTURE0;
		if (target_vertex_array != vertex_array) {
			matchGLClientState(GL11.GL_VERTEX_ARRAY, target_vertex_array);
			vertex_array = target_vertex_array;
		}
		boolean target_normal_array = (client_flags & NORMAL_ARRAY) != 0;
		if (target_normal_array != normal_array) {
			matchGLClientState(GL11.GL_NORMAL_ARRAY, target_normal_array);
			normal_array = target_normal_array;
		}
		boolean target_texcoord0_array = (client_flags & TEXCOORD0_ARRAY) != 0;
		if (target_texcoord0_array != texcoord0_array) {
			matchGLClientState(GL11.GL_TEXTURE_COORD_ARRAY, target_texcoord0_array);
			texcoord0_array = target_texcoord0_array;
		}
		boolean target_texcoord1_array = (client_flags & TEXCOORD1_ARRAY) != 0;
		if (target_texcoord1_array != texcoord1_array) {
			clientActiveTexture(GL13.GL_TEXTURE1);
			matchGLClientState(GL11.GL_TEXTURE_COORD_ARRAY, target_texcoord1_array);
			clientActiveTexture(GL13.GL_TEXTURE0);
			texcoord1_array = target_texcoord1_array;
		}
		boolean target_color_array = (client_flags & COLOR_ARRAY) != 0;
		if (target_color_array != color_array) {
			matchGLClientState(GL11.GL_COLOR_ARRAY, target_color_array);
			color_array = target_color_array;
		}
	}
 
Example #25
Source Project: opsu   Author: itdelatrisu   File: LegacyCurveRenderState.java    License: 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 #26
Source Project: FEMultiplayer   Author: chudooder   File: PaletteSwapper.java    License: 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 #27
Source Project: LWJGUI   Author: orange451   File: BlurPane.java    License: 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 #28
Source Project: LWJGUI   Author: orange451   File: GenericShader.java    License: 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 #29
Source Project: LWJGUI   Author: orange451   File: OffscreenBuffer.java    License: 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 #30
Source Project: OpenGL-Animation   Author: TheThinMatrix   File: Texture.java    License: The Unlicense 4 votes vote down vote up
public void bindToUnit(int unit) {
	GL13.glActiveTexture(GL13.GL_TEXTURE0 + unit);
	GL11.glBindTexture(type, textureId);
}