My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
79
80
81
82
83
84
85
86
87
88
package com.badlogic.gamedev.samples;

import java.io.IOException;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
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.MeshLoader;
import com.badlogic.gamedev.tools.Texture;
import com.badlogic.gamedev.tools.Mesh.PrimitiveType;
import com.badlogic.gamedev.tools.Texture.TextureFilter;
import com.badlogic.gamedev.tools.Texture.TextureWrap;

public class ObjSample extends GameActivity implements GameListener
{
Mesh mesh;
Texture texture;
float angle = 0;

public void onCreate( Bundle savedInstance )
{
super.onCreate( savedInstance );
setGameListener( this );
}

@Override
public void setup(GameActivity activity, GL10 gl)
{
try {
mesh = MeshLoader.loadObj( gl, getAssets().open( "ship.obj" ) );
Bitmap bitmap = BitmapFactory.decodeStream( getAssets().open( "ship.png" ) );
texture = new Texture( gl, bitmap, TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge );
bitmap.recycle();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException( "Couldn't load mesh" );
}

float[] lightColor = { 1, 1, 1, 1 };
float[] ambientLightColor = {0.0f, 0.0f, 0.0f, 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, 0.5f, 0, 0 };
gl.glLightfv( GL10.GL_LIGHT0, GL10.GL_POSITION, direction, 0 );
gl.glEnable( GL10.GL_COLOR_MATERIAL );

gl.glEnable( GL10.GL_TEXTURE_2D );
texture.bind();

gl.glRotatef( angle, 0, 1, 0 );

mesh.render( PrimitiveType.Triangles );

angle+= activity.getDeltaTime() * 180; // wir drehen uns um 180 Grad pro Sekunde
if( angle > 360 )
angle = 0;
}
}

Change log

r33 by quantumgame on Jan 10, 2010   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r28 by quantumgame on Jan 9, 2010   Diff
[No log message]
r25 by quantumgame on Jan 9, 2010   Diff
[No log message]
All revisions of this file

File info

Size: 2784 bytes, 88 lines
Powered by Google Project Hosting