My favorites
▼
|
Sign in
android-gamedev
Android Game Development Tutorial Code
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
src
/
com
/
badlogic
/
gamedev
/
samples
/
LightSample.java
‹r22
r71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.badlogic.gamedev.samples;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLU;
import android.os.Bundle;
import com.badlogic.gamedev.tools.GameActivity;
import com.badlogic.gamedev.tools.GameListener;
import com.badlogic.gamedev.tools.Mesh;
import com.badlogic.gamedev.tools.Mesh.PrimitiveType;
public class LightSample extends GameActivity implements GameListener
{
Mesh mesh;
public void onCreate( Bundle savedInstance )
{
super.onCreate( savedInstance );
setGameListener( this );
}
@Override
public void setup(GameActivity activity, GL10 gl)
{
mesh = new Mesh( gl, 9, false, false, true );
mesh.normal( 0, 0, 1 );
mesh.vertex( 1, 0, 0 );
mesh.normal( 0, 0, 1 );
mesh.vertex( 1, 1, 0 );
mesh.normal( 0, 0, 1 );
mesh.vertex( 0, 1, 0 );
mesh.normal( 1, 0, 0 );
mesh.vertex( 1, 0, 0 );
mesh.normal( 1, 0, 0 );
mesh.vertex( 1, 0, -1);
mesh.normal( 1, 0, 0 );
mesh.vertex( 1, 1, 0 );
mesh.normal( 0, 1, 0 );
mesh.vertex( 1, 1, 0 );
mesh.normal( 0, 1, 0 );
mesh.vertex( 1, 1, -1 );
mesh.normal( 0, 1, 0 );
mesh.vertex( 0, 1, 0 );
float[] lightColor = { 1, 1, 1, 1 };
float[] ambientLightColor = {0.2f, 0.2f, 0.2f, 1 };
gl.glLightfv( GL10.GL_LIGHT0, GL10.GL_AMBIENT, ambientLightColor, 0 );
gl.glLightfv( GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightColor, 0 );
gl.glLightfv( GL10.GL_LIGHT0, GL10.GL_SPECULAR, lightColor, 0 );
}
@Override
public void mainLoopIteration(GameActivity activity, GL10 gl)
{
gl.glClear( GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT );
gl.glViewport( 0, 0, activity.getViewportWidth(), activity.getViewportHeight() );
gl.glEnable( GL10.GL_DEPTH_TEST );
gl.glMatrixMode( GL10.GL_PROJECTION );
gl.glLoadIdentity();
float aspectRatio = (float)activity.getViewportWidth() / activity.getViewportHeight();
GLU.gluPerspective( gl, 67, aspectRatio, 1, 100 );
gl.glMatrixMode( GL10.GL_MODELVIEW );
gl.glLoadIdentity();
GLU.gluLookAt( gl, 3, 3, 3, 0.5f, 0.5f, -0.5f, 0, 1, 0 );
gl.glEnable( GL10.GL_LIGHTING );
gl.glEnable( GL10.GL_LIGHT0 );
float[] direction = { 1 / (float)Math.sqrt(2), 1 / (float)Math.sqrt(2), 0, 0 };
gl.glLightfv( GL10.GL_LIGHT0, GL10.GL_POSITION, direction, 0 );
gl.glEnable( GL10.GL_COLOR_MATERIAL );
mesh.render( PrimitiveType.Triangles );
}
}
Show details
Hide details
Change log
r24
by quantumgame on Jan 9, 2010
Diff
[No log message]
Go to:
/trunk/.settings
...org.eclipse.core.resources.prefs
/trunk/AndroidManifest.xml
...c/com/badlogic/gamedev/Main.java
...gamedev/samples/LightSample.java
...amples/TransformationSample.java
/trunk/tutorial/tutorial.txt
Project members,
sign in
to write a code review
Older revisions
r22
by quantumgame on Jan 8, 2010
Diff
[No log message]
r21
by quantumgame on Jan 8, 2010
Diff
[No log message]
All revisions of this file
File info
Size: 2359 bytes, 78 lines
View raw file
Powered by
Google Project Hosting