Problem beim Rendern von 3D-Objekt

!GH!Budd

Mitglied
Hallo zusammen!

Ich hab hier mal dann und wann mitgelesen und auch schon den einen oder anderen Post geschrieben, allergdings noch kein eigenes Problem gehabt. Ich wage mich in die Welt der OpenGL-Programmierung unter Android. Vielleicht ist es hier dafür nicht der richtige Bereich, wir werden sehen.

Ich habe aus einem Buch ein Stück Quelltext verändert, das mir ein mit Blender erstelltes 3D-Objekt samt Textur laden und rendern soll. Im Buch wird zunächst ein framework implementiert, das einen OBJ-Parser enthält, den ich auch verwende.
Mein Problem ist, dass das fertig gerenderte Objekt so aussieht:

screen.png


Das ist der entsprechende Quelltext:
Java:
package com.badlogic.androidgames.gladvanced;

import javax.microedition.khronos.opengles.GL10;

import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Screen;
import com.badlogic.androidgames.framework.gl.Camera2D;
import com.badlogic.androidgames.framework.gl.EulerCamera;
import com.badlogic.androidgames.framework.gl.ObjLoader;
import com.badlogic.androidgames.framework.gl.PointLight;
import com.badlogic.androidgames.framework.gl.SpriteBatcher;
import com.badlogic.androidgames.framework.gl.Texture;
import com.badlogic.androidgames.framework.gl.TextureRegion;
import com.badlogic.androidgames.framework.gl.Vertices3;
import com.badlogic.androidgames.framework.impl.GLGame;
import com.badlogic.androidgames.framework.impl.GLScreen;
import com.badlogic.androidgames.framework.math.Vector2;
import com.badlogic.androidgames.framework.math.Vector3;

public class ObjTest extends GLGame {

	@Override
	public Screen getStartScreen() {
		return new ObjScreen(this);
	}

	class ObjScreen extends GLScreen {

		//Texture crateTexture;
		Texture carTexture;
		//Vertices3 cube;
		Vertices3 car;
		PointLight light;
		EulerCamera camera;
		Texture buttonTexture;
		SpriteBatcher batcher;
		Camera2D guiCamera;
		TextureRegion buttonRegion;
		Vector2 touchPos;
		float lastX = -1;
		float lastY = -1;

		public ObjScreen(Game game) {
			super(game);

			//crateTexture = new Texture(glGame, "crate.png", true);
			carTexture = new Texture(glGame, "car.png", true);
			//cube = ObjLoader.load(glGame, "cube.obj");
			car = ObjLoader.load(glGame, "car.obj");
			light = new PointLight();
			light.setPosition(3, 3, -3);
			camera = new EulerCamera(67, glGraphics.getWidth()
					/ (float) glGraphics.getHeight(), 1, 100);
			camera.getPosition().set(0, 1, 3);

			buttonTexture = new Texture(glGame, "button.png");
			batcher = new SpriteBatcher(glGraphics, 1);
			guiCamera = new Camera2D(glGraphics, 480, 320);
			buttonRegion = new TextureRegion(buttonTexture, 0, 0, 64, 64);
			touchPos = new Vector2();
		}

		@Override
		public void resume() {
			//crateTexture.reload();
			carTexture.reload();
		}

		@Override
		public void update(float deltaTime) {
			game.getInput().getTouchEvents();
			float x = game.getInput().getTouchX(0);
			float y = game.getInput().getTouchY(0);
			guiCamera.touchToWorld(touchPos.set(x, y));

			if (game.getInput().isTouchDown(0)) {
				if (touchPos.x < 64 && touchPos.y < 64) {
					Vector3 direction = camera.getDirection();
					camera.getPosition().add(direction.mul(deltaTime));
				} else {
					if (lastX == -1) {
						lastX = x;
						lastY = y;
					} else {
						camera.rotate((x - lastX) / 10, (y - lastY) / 10);
						lastX = x;
						lastY = y;
					}
				}
			} else {
				lastX = -1;
				lastY = -1;
			}
		}

		@Override
		public void present(float deltaTime) {
			GL10 gl = glGraphics.getGL();
			gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
			gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());

			camera.setMatrices(gl);

			gl.glEnable(GL10.GL_DEPTH_TEST);
			gl.glEnable(GL10.GL_TEXTURE_2D);
			gl.glEnable(GL10.GL_LIGHTING);
			gl.glEnable(GL10.GL_COLOR_MATERIAL);

			
			
			//crateTexture.bind();
			//cube.bind();
			carTexture.bind();
			car.bind();
			light.enable(gl, GL10.GL_LIGHT0);

			
					gl.glPushMatrix();
					gl.glTranslatef(0, 0, -4);
					
					//cube.draw(GL10.GL_TRIANGLES, 0, cube.getNumVertices());
					car.draw(GL10.GL_TRIANGLES, 0, car.getNumVertices());
					
					gl.glPopMatrix();
			
		

			//cube.unbind();
			car.unbind();
			
			gl.glDisable(GL10.GL_COLOR_MATERIAL);
			gl.glDisable(GL10.GL_LIGHTING);
			gl.glDisable(GL10.GL_DEPTH_TEST);

			gl.glEnable(GL10.GL_BLEND);
			gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

			guiCamera.setViewportAndMatrices();
			batcher.beginBatch(buttonTexture);
			batcher.drawSprite(32, 32, 64, 64, buttonRegion);
			batcher.endBatch();

			gl.glDisable(GL10.GL_BLEND);
			gl.glDisable(GL10.GL_TEXTURE_2D);
		}

		@Override
		public void pause() {

		}

		@Override
		public void dispose() {
		}
	}
}
Ich kann natürlich auch gerne noch mehr Quelltexte posten (z.B. von dem ObjLoader), aber ich denke wenn sich jemand schonmal damit beschäftigt hat, ist demjenigen vielleicht schnell klar, woran es liegen könnte.

Falls noch andere Informationen gebraucht werden, gerne nachfragen.

Vielen Dank für zahlreiche hilfreiche Antworten im Vorraus! :toll:
 
Zuletzt bearbeitet:
Ähnliche Java Themen
  Titel Forum Antworten Datum
DaniSahne96 Problem beim Appdebuggen auf Smartphone Android & Cross-Platform Mobile Apps 3
P Android Problem beim Widget - Denkfehler ? Android & Cross-Platform Mobile Apps 2
V [Java] und [JavaME] ClientServer StreamConnection . Problem beim lesen / schreiben Android & Cross-Platform Mobile Apps 2
R Ein Problem beim ausführen von folgendem Quelltext Android & Cross-Platform Mobile Apps 11
A Problem beim Subtrahieren eines Double von einem Double Android & Cross-Platform Mobile Apps 5
F Problem beim Erstellen der Jar File Android & Cross-Platform Mobile Apps 4
W Prüfen, ob App auf Gerät installiert ist Problem S10 Android & Cross-Platform Mobile Apps 11
W In App Purchase Problem? Android & Cross-Platform Mobile Apps 36
W Problem mit Android Studio Android & Cross-Platform Mobile Apps 0
T Android R.string.test+i Problem Android & Cross-Platform Mobile Apps 2
K Android to Pi | Websocket Problem Android & Cross-Platform Mobile Apps 3
N Intent und finish() Problem Android & Cross-Platform Mobile Apps 5
B Android App Programmierung Einsteiger Problem Android & Cross-Platform Mobile Apps 4
emeraldo Android Problem mit Bottomnavmenu Android & Cross-Platform Mobile Apps 10
I Das Problem mit der Tastatur... android:windowSoftInputMode="adjustPan" Android & Cross-Platform Mobile Apps 1
M Android App → Problem mit dem Speichern von einem Bitmap–Objekt. Android & Cross-Platform Mobile Apps 1
A Android Android Studio Emulator Problem Android & Cross-Platform Mobile Apps 1
S Android Studio Bluetooth App Problem Android & Cross-Platform Mobile Apps 6
J TicTacToe Problem bei kontrolle Android & Cross-Platform Mobile Apps 7
J Button array ID Problem Android & Cross-Platform Mobile Apps 2
M Problem bei Werteübergabe, MSQL verbindung Android & Cross-Platform Mobile Apps 3
S Android Problem mit Android Virtual Device erstellung. Android & Cross-Platform Mobile Apps 2
Anfänger2011 Text to Speech Problem Android & Cross-Platform Mobile Apps 1
S Android Android java onclick listener Problem Android & Cross-Platform Mobile Apps 9
A Android Problem mit ListView und OnItemClickListener.. Android & Cross-Platform Mobile Apps 10
K Problem mit arraylist und button Android & Cross-Platform Mobile Apps 16
R W-Lan Problem über Sockets Android & Cross-Platform Mobile Apps 1
P ViewPager Problem Android & Cross-Platform Mobile Apps 1
A Android Problem mit Video von Youtube abspielen Android & Cross-Platform Mobile Apps 4
A Android Problem mit Zurücktaste und ausgabe der Aktuellen Seite Android & Cross-Platform Mobile Apps 6
B Android Problem mit Soundwiedergabe Android & Cross-Platform Mobile Apps 2
T Android Android Sensor: Java Problem Android & Cross-Platform Mobile Apps 1
L Android Gyroscope Sensor Problem Android & Cross-Platform Mobile Apps 2
S Android GPS Problem Android & Cross-Platform Mobile Apps 24
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 1
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 0
B Android Problem mit Rückgabewert Android & Cross-Platform Mobile Apps 13
L Android komisches Bitmap-Größe-Problem Android & Cross-Platform Mobile Apps 8
D Android Layout Problem Android & Cross-Platform Mobile Apps 2
R Problem mit View in ScrollView Android & Cross-Platform Mobile Apps 6
R Eclipse + AndroidSDK - Problem mit Referenzen Android & Cross-Platform Mobile Apps 6
M Problem mit setOnClickListener Android & Cross-Platform Mobile Apps 4
M GCM IntentService Problem Android & Cross-Platform Mobile Apps 3
D Android Gallery Problem Android & Cross-Platform Mobile Apps 5
P Problem mit Cell id Android & Cross-Platform Mobile Apps 6
L Android Problem mit "spinner" Android & Cross-Platform Mobile Apps 10
D Android problem mit geschwindigkeitsberechnung app Android & Cross-Platform Mobile Apps 2
E Android Problem mit Contact Provider Android & Cross-Platform Mobile Apps 1
H Android Problem mit ListActivity Android & Cross-Platform Mobile Apps 3
S Android Layout Problem mit fill_parent Android & Cross-Platform Mobile Apps 5
F Android ExpandableList, SimpleCursorTreeAdapter, Cursor Problem Android & Cross-Platform Mobile Apps 2
A Android Problem mit Long.getLong() bzw. Integer.getInteger() Android & Cross-Platform Mobile Apps 2
A Problem mit HTTP- Verbindung Android & Cross-Platform Mobile Apps 4
F Eclipse JAD File erzeugen -- Problem Android & Cross-Platform Mobile Apps 10
M Problem mit dem Auslesen von System Properties Android & Cross-Platform Mobile Apps 7
P wtk problem Android & Cross-Platform Mobile Apps 3
G Math exp() Problem Android & Cross-Platform Mobile Apps 4
G S40 Problem Android & Cross-Platform Mobile Apps 8
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
S Image Problem Android & Cross-Platform Mobile Apps 11
M Problem mit den Softkeys Android & Cross-Platform Mobile Apps 4
G J2ME jar-problem Android & Cross-Platform Mobile Apps 10
S Komisches Problem Android & Cross-Platform Mobile Apps 3
A Problem: Canvas-Grösse Motorola RAZR v3r Android & Cross-Platform Mobile Apps 8
S Problem mit Einbindung einer externer Bibliothek Android & Cross-Platform Mobile Apps 2
G Random - Problem Android & Cross-Platform Mobile Apps 5
E problem mit den resourcen Android & Cross-Platform Mobile Apps 2
O Problem mit Datagramconnection Android & Cross-Platform Mobile Apps 2
P Problem mit der Uhrzeit Android & Cross-Platform Mobile Apps 2
S Problem auf dem Handy Android & Cross-Platform Mobile Apps 3
R Android Löschfunktion beim Wischen Android & Cross-Platform Mobile Apps 10
W Rand ändern beim ImageView bei Picasso Android & Cross-Platform Mobile Apps 1
Arif Android Android Studio: Fehler beim Einbinden fremder Bibliothek? Android & Cross-Platform Mobile Apps 2
L App stürtzt ab beim öffnen Android & Cross-Platform Mobile Apps 1
JavaWolf165 Android Fehler beim Speichern/Downloaden einer Datei Android & Cross-Platform Mobile Apps 2
S Android Probleme beim Verbinden mit einer HTTPS Seite Android & Cross-Platform Mobile Apps 4
M Android Fehler beim Parsen. Android & Cross-Platform Mobile Apps 29
V Android Fehlermeldung beim Öffnen von Eclipse nach Installation der Android Erweiterung Android & Cross-Platform Mobile Apps 4
M Error beim drücken der Zurück-Taste am Handy Android & Cross-Platform Mobile Apps 2
S Fehler beim Textdatei einlesen!? Android & Cross-Platform Mobile Apps 7
A Fehlermeldung beim ändern der ViewGroup. Android & Cross-Platform Mobile Apps 6
H Buttons färben sich mit, beim Hintergrund ändern Android & Cross-Platform Mobile Apps 3
A Mehrere Fehler beim Compilieren Android & Cross-Platform Mobile Apps 4
L Android OutOfMemory beim erneuten Starten der App Android & Cross-Platform Mobile Apps 2
N Android Retain Dialog verschwindet beim drehen Android & Cross-Platform Mobile Apps 4
B Android GameLoopThread stürzt beim 2ten start der App ab? Android & Cross-Platform Mobile Apps 4
K Nullpointer beim Löschen von Datenbankeintrag, je nachdem wo der Befehl steht Android & Cross-Platform Mobile Apps 5
S Java ME Exception beim Abspielen von Musik Android & Cross-Platform Mobile Apps 6
G Fehler beim Import "Invalid project description" Android & Cross-Platform Mobile Apps 2
G unterschiedliches Verhalten beim Installieren des App auf dem Smartphone Android & Cross-Platform Mobile Apps 3
K Android schwarzer Bildschirm beim Rendern von Text und Dreiecken Android & Cross-Platform Mobile Apps 9
A Fehler beim Starten eines Intents - alles in einer Klasse funktioniert... Android & Cross-Platform Mobile Apps 4
J Android Verhalten beim Hinzufügen neuer Views? Android & Cross-Platform Mobile Apps 6
S Android Fehler beim Anzeigen meines Apps auf Galaxy Tab Android & Cross-Platform Mobile Apps 4
G Beziehung von THIS beim Imageadapter und AsyncTask Android & Cross-Platform Mobile Apps 7
N Error in HTTP operation beim KXML parsen Android & Cross-Platform Mobile Apps 7
G fehldermeldung beim klicken auf "build" Android & Cross-Platform Mobile Apps 8
L SecurityException beim lesen/schreiben eine Datei Android & Cross-Platform Mobile Apps 7
S createPlayer beim Entwickeln Android & Cross-Platform Mobile Apps 6
K Android Videos rendern Android & Cross-Platform Mobile Apps 1

Ähnliche Java Themen

Neue Themen


Oben