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

The following examples show how to use org.lwjgl.opengl.GL11#glLight() . 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: Renderer.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
private final void initVisibleGL() {
	if (Settings.getSettings().fullscreen_depth_workaround) {
		IntBuffer dummy_buf = BufferUtils.createIntBuffer(1);
		GL11.glReadPixels(0, 0, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_UNSIGNED_INT, dummy_buf);
	}

	FloatBuffer float_array = BufferUtils.createFloatBuffer(4);
	GL11.glEnable(GL11.GL_LIGHT0);
	float[] light_diff_color = {1.0f, 1.0f, 1.0f, 1.0f};
	float_array.put(light_diff_color);
	float_array.rewind();
	GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, float_array);
	GL11.glLightModeli(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

	float[] global_ambient = {0.65f, 0.65f, 0.65f, 1.0f};
	float_array.put(global_ambient);
	float_array.rewind();
	GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, float_array);
	float[] material_color = {1.0f, 1.0f, 1.0f, 1.0f};
	float_array.put(material_color);
	float_array.rewind();
	GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE, float_array);
	Display.update();
}
 
Example 2
Source File: SlickCallableTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Render the GL scene, this isn't efficient and if you know 
 * OpenGL I'm assuming you can see why. If not, you probably
 * don't want to use this feature anyway
 */
public void renderGL() {		
	FloatBuffer pos = BufferUtils.createFloatBuffer(4);
	pos.put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}).flip();
	FloatBuffer red = BufferUtils.createFloatBuffer(4);
	red.put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}).flip();

	GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
	GL11.glEnable(GL11.GL_LIGHT0);

	GL11.glEnable(GL11.GL_CULL_FACE);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_LIGHTING);
	
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	float h = (float) 600 / (float) 800;
	GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();	
	GL11.glTranslatef(0.0f, 0.0f, -40.0f);	
	GL11.glRotatef(rot,0,1,1);		
	
	GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red);
	gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
}
 
Example 3
Source File: DefaultRenderer.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public void render(AmbientAudio ambient, CameraState frustum_state, GUIRoot gui_root) {
		ambient.updateSoundListener(frustum_state, world.getHeightMap());
		if (Globals.line_mode || cheat.line_mode) {
			GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
			GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_LINE);
		}

		GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, light_array);
		if (Globals.draw_sky) {
			sky.render();
		}

		fog_info.enableFog(frustum_state.getCurrentZ());
		if (Globals.draw_sky) {
			sky.renderSeaBottom();
		}

		// render landscape (must be before trees and misc, cause they use data calculated here)
		if (Globals.process_landscape) {
			landscape_renderer.prepareAll(frustum_state, false);
			landscape_renderer.renderAll();
		}
		// frustum check and placement
		if (Globals.process_trees) {
			tree_renderer.setup(frustum_state);
			world.getTreeRoot().visit(tree_renderer);
		}
		if (Globals.process_misc) {
			element_renderer.setup(frustum_state);
			world.getElementRoot().visit(element_renderer);
		}
		
		// Sort sprites
		sprite_sorter.distributeModels();
		
		// render shadows
		if (Globals.process_shadows) {
			render_queues.renderShadows(landscape_renderer);
		}

		gui_root.getDelegate().render3D(landscape_renderer, render_queues);
		
		// render
		if (Globals.process_trees) {
			tree_renderer.renderAll();
		}
		if (Globals.process_misc) {
			render_queues.renderAll();
		}

		drawAxes();

		if (Globals.draw_water)
			water.render(sky);

		if (Globals.process_misc) 
			render_queues.renderBlends();

		LightningRenderer.render(render_queues, element_renderer.getRenderState().getLightningQueue(), frustum_state);
		EmitterRenderer.render(render_queues, element_renderer.getRenderState().getEmitterQueue(), frustum_state);
		renderRallyPoint(frustum_state);

/*		float landscape_x = GUIRoot.getGUIRoot().getLandscapeLocationX();
		float landscape_y = GUIRoot.getGUIRoot().getLandscapeLocationY();
		if (Globals.isBoundsEnabled(Globals.BOUNDING_REGIONS)) {
			UnitGrid.getGrid().debugRenderRegions(landscape_x, landscape_y);
		}
*/
		if (Globals.isBoundsEnabled(Globals.BOUNDING_OCCUPATION)) {
			picker.debugRender();
		}

/*		if (Globals.isBoundsEnabled(Globals.BOUNDING_UNIT_GRID)) {
			java.util.Iterator it = com.oddlabs.tt.model.SelectionArmy.getSelection().getSet().iterator();
			while (it.hasNext()) {
				Object next = it.next();
				if (next instanceof com.oddlabs.tt.model.Unit) {
					com.oddlabs.tt.model.Unit s_unit = (com.oddlabs.tt.model.Unit)next;
					s_unit.debugRender();
				}
			}
//			UnitGrid.getGrid().debugRender(landscape_x, landscape_y);
		}*/
		fog_info.disableFog();
		if (Globals.line_mode || (cheat.line_mode)) {
			GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
			GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_FILL);
		}
	}