8 Replies - 2060 Views - Last Post: 29 November 2010 - 06:48 PM

#1 geem42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-March 08

.equals is broken ... not working as expected

Posted 28 November 2010 - 09:56 PM

So this one is really stumping me, I have a class that I'm writing for Android, and the namespace looks like so:

public class AcObject {

	/** Our texture pointer */
	private int[] textures = new int[3];

	// objects properties
	private String name = "";
	private String data = "";
	private String texture = "none";


See the
private String texture = "none";
this is important.

Later, when I load textures in the same class I use this:

	public void loadGLTexture(GL10 gl, Context context) {

		if (this.texture.equals("none")) {
			Log.i("AcLoader", ">>>> NO TEXTURE TO LOAD");
			return;
		} else
			Log.i("AcLoader", ">>>> LOADING TEX: " + this.texture);



The Log.i call just outputs to the debug log for android, so I can see what my code's doing

this part:
if (this.texture.equals("none")) {

works perfectly! I can tell by viewing the output log, and all the AcObjects that don't have textures report "NO TEXTURE TO LOAD"

However...

When I attempt to Draw, I use the following code:

	public void draw(GL10 gl, int filter) {
		// Bind the texture according to the set texture filter
		if(!this.texture.equals("none"))
			gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);


The condition:
if(!this.texture.equals("none"))


Always evaluates false and the ! flips it to true. Note that, from the time the texture is attempted to load, the model is already done loading, and nothing would / should modify the this.texture at all.

Further, if I print the this.texture to the log, it prints "none"

so I KNOW that this.texture DOES equal "none" because I print it to the log... yet this always evaluates as !(false)

Whats going on? Tearing my hair out... :whatsthat:

-Greg



Edit: hit post by mistake, sorry

This post has been edited by geem42: 28 November 2010 - 10:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: .equals is broken ... not working as expected

#2 geem42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-March 08

Re: .equals is broken ... not working as expected

Posted 28 November 2010 - 10:26 PM

Bump.. anybody have this error before? I can provide any information / code samples needed.

I'm pretty sure I broke Java, since there is NO reason for this to be happening. If I broke Java on my first Java project... well no more Java for me!
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10561
  • View blog
  • Posts: 39,079
  • Joined: 27-December 08

Re: .equals is broken ... not working as expected

Posted 28 November 2010 - 10:31 PM

*Moved to Android*

Can you post all your code? Also, most posts are answered within 48 hours rather than 30 minutes. Please be patient. We are all volunteers here and will help as best as we are able. :)
Was This Post Helpful? 0
  • +
  • -

#4 geem42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-March 08

Re: .equals is broken ... not working as expected

Posted 28 November 2010 - 10:51 PM

View Postmacosxnerd101, on 28 November 2010 - 09:31 PM, said:

*Moved to Android*

Can you post all your code? Also, most posts are answered within 48 hours rather than 30 minutes. Please be patient. We are all volunteers here and will help as best as we are able. :)


I'm new to Java so critique would help, also I don't think is is an Android related issue because the String class and .equals method are part of Java. Android is working just fine.

Also this is a work in progress, especially the Draw function, but here's all my code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;
import android.util.Log;

/**
 * This class is loads and displays an Object
 * 
 * @author Greg Miller
 */
public class AcObject {

	/** Our texture pointer */
	private int[] textures = new int[3];

	// objects properties
	private String name = "";
	private String data = "";
	private String texture = "none";
	private float texrepX = 1.0f;
	private float texrepY = 1.0f;
	private String url = "";
	private int numvert = 0;
	private int numsurf = 0;
	private int numkids = 0;

	/** The buffer holding the vertices */
	private FloatBuffer vertexBuffer;
	/** The buffer holding the texture coordinates */
	private FloatBuffer textureBuffer;
	/** The buffer holding the indices */
	private ShortBuffer indexBuffer;
	/** The buffer holding the normals */
	// private FloatBuffer normalBuffer;

	// holds all the child objects
	private ArrayList<AcObject> kids;

	// Collection of vertices
	float verts[];
	float indicies[];

	// Collection of faces
	short faces[];
	float uv[];
	int fPos;

	/**
	 * The Ac Object constructor.
	 * 
	 * Load the object from a buffered reader then prepare the buffers for
	 * drawing
	 */
	public AcObject(BufferedReader reader, Context context, GL10 gl) {

		Log.i("AcLoader", ">>>> NEW OBJECT");

		String line, tok;
		boolean done = false;
		try {
			while (!done) {

				// get the next line
				line = reader.readLine();

				// make sure the line has content
				if (line.length() > 0) {

					// Get the keyword, and behave properly
					tok = AssetReader.firstWord(line);

					// act based on the first word:
					if (tok.equals("name")) {
						// save the name
						this.name = line.substring(5).trim();
						Log.i("AcLoader", ">>>> OB NAME: " + this.name);
					} else if (tok.equals("data")) {
						// save the data!
						this.data = reader.readLine();
						Log.i("AcLoader", ">>>> OB DATA: " + this.data);
					} else if (tok.equals("texture")) {
						// save the texture
						this.texture = line.substring(8).trim();
						Log.i("AcLoader", ">>>> OB TEXTURE: " + this.texture);
					} else if (tok.equals("texrep")) {
						// TODO: program in texture repeat parsing
						texrepX = 1.0f;
						texrepY = 1.0f;
						Log.i("AcLoader", ">>>> TEX REP: 1.0, 1.0");
					} else if (tok.equals("rot")) {
						// TO DO: program in rotation loading
					} else if (tok.equals("loc")) {
						// TO DO: program in location loading
					} else if (tok.equals("url")) {
						// save the URL
						this.url = line.substring(4).trim();
						Log.i("AcLoader", ">>>> OB URL: " + this.url);
					} else if (tok.equals("numvert")) {
						// save the number of vertices
						this.numvert = Integer.parseInt(line.substring(8)
								.trim());

						Log.i("AcLoader", ">>>> OB NUMBER OF VERTICES: "
								+ this.numvert);

						// we have vertices, so lets makes a new array list
						verts = new float[(this.numvert * 3)];

						// LOAD all the vertices!
						readVerts(reader);

					} else if (tok.equals("numsurf")) {

						// save the number of surfaces
						this.numsurf = Integer.parseInt(line.substring(8)
								.trim());

						Log.i("AcLoader", ">>>> OB NUMBER OF SURFACES: "
								+ this.numsurf);

						// LOAD all the surfaces!
						readSurfs(reader);

					} else if (tok.equals("kids")) {

						// save the number of children
						this.numkids = Integer.parseInt(line.substring(5)
								.trim());

						Log.i("AcLoader", ">>>> OB NUMBER OF CHILDREN: "
								+ this.numkids);

						// LOAD all the children!
						if (this.numkids > 0) {

							// make a new ArrayList for the kids:
							kids = new ArrayList<AcObject>();

							for (int i = 0; i < this.numkids; i++) {
								kids.add(new AcObject(reader, context, gl));
							}// next i
						}

						// when "kids" is reached, the entire object has been
						// loaded!
						done = true;
					}
				}// has content

			}// wend

		} catch (IOException e) {
			e.printStackTrace();
		}// tried

		// Now that we've successfully loaded the model, lets make the OpenGL
		// arrays

		// vertex array
		ByteBuffer byteBuf = ByteBuffer.allocateDirect(indicies.length * 4);
		byteBuf.order(ByteOrder.nativeOrder());
		vertexBuffer = byteBuf.asFloatBuffer();
		vertexBuffer.put(indicies);
		vertexBuffer.position(0);

		// UV-coordiantes texture array
		byteBuf = ByteBuffer.allocateDirect(uv.length * 4);
		byteBuf.order(ByteOrder.nativeOrder());
		textureBuffer = byteBuf.asFloatBuffer();
		textureBuffer.put(uv);
		textureBuffer.position(0);

		/*
		 * not used for now TODO: calculate normals byteBuf =
		 * ByteBuffer.allocateDirect(normals.length * 4);
		 * byteBuf.order(ByteOrder.nativeOrder()); normalBuffer =
		 * byteBuf.asFloatBuffer(); normalBuffer.put(normals);
		 * normalBuffer.position(0);
		 */

		// faces / surfaces array
		byteBuf = ByteBuffer.allocateDirect(faces.length * 2);
		byteBuf.order(ByteOrder.nativeOrder());
		indexBuffer = byteBuf.asShortBuffer();
		indexBuffer.put(faces);
		indexBuffer.position(0);

	}// AcObject constructor

	// PARSING METHODS +++ PARSING METHODS +++ PARSING METHODS +++ PARSING
	// METHODS
	/**
	 * Reads all the vertices for this object...
	 */
	private void readVerts(BufferedReader reader) {

		// strings for parsing the file
		String line, v[];
		try {
			// loop to load all the vertices
			for (int i = 0; i < this.numvert; i++) {

				// get the next line...
				line = reader.readLine();

				// break it into an array
				v = line.split(" ");

				// add each element to the vert array
				for (int vi = 0; vi < 3; vi++) {
					// add the vertex
					verts[((i * 3) + vi)] = (Float.valueOf(v[vi]));
				}// next vi
			}// next i

		} catch (IOException e) {
			// e.printStackTrace();
		}

		Log.i("AcLoader", ">>>> VERTICES FINISHED LOADING!");
	}// readVerts

	/**
	 * Reads all the surfaces for this object...
	 */
	private void readSurfs(BufferedReader reader) {

		// we have surfaces (faces) so lets make a new arrays
		indicies = new float[(this.numsurf * 9)];
		faces = new short[(this.numsurf * 3)];
		uv = new float[((this.numsurf * 3) * 2)];

		fPos = 0;
		// loop to load all the vertices
		for (int i = 0; i < this.numsurf; i++) {
			// load the next surface..
			loadSurf(reader);
		}// next i

		Log.i("AcLoader", ">>>> SURFACES FINISHED LOADING!");

		// done loading the faces / surfaces, so lets clear the old verts..
		verts = null;
	}// readSurfs

	/**
	 * Reads all the surfaces for this object...
	 */
	private void loadSurf(BufferedReader reader) {

		/*
		 * skip lines until face data starts TODO: read material, if necessary
		 * NOTE: because we are doing openGL ES, we will assume that all the
		 * lines in the file are for triangles the program (in my personal case,
		 * Blender (http://www.blender3d.org/) has the option to export
		 * triangles only.
		 * 
		 * I am not about to program some super-magic interpreter to convert
		 * quads to triangles, as such this code assumes that all POLYS in the
		 * AC file are equivalent to "refs 3"
		 */
		try {
			while (!AssetReader.firstWord(reader.readLine()).equals("refs")) {
			}// wend
		} catch (IOException e) {
			e.printStackTrace();
		}

		/*
		 * now that we skipped the unnecessary header part, lets load the
		 * surfaces! specifically we will load the next three vertex indices
		 * into the faces arrayList
		 */
		String line, f[];
		int Face;
		for (int i = 0; i < 3; i++) {

			try {
				// get the next line...
				line = reader.readLine();

				// break it into an array
				f = line.split(" ");

				/*
				 * add only the first value to the face array, because the other
				 * two are UV coordinates for textures
				 */
				// get the face
				Face = (Short.valueOf(f[0]));

				// add its coordinates to the indicies list
				indicies[((fPos * 3))] = verts[((Face * 3))];
				indicies[((fPos * 3) + 1)] = verts[((Face * 3) + 1)];
				indicies[((fPos * 3) + 2)] = verts[((Face * 3) + 2)];

				// seems kinda redundant but necessary for texture to work...
				faces[fPos] = (short) fPos;

				// read UV texture coordinates
				uv[(fPos * 2)] = (Float.valueOf(f[1]));
				uv[(fPos * 2 + 1)] = (1.0f - Float.valueOf(f[2]));

				fPos++;

			} catch (IOException e) {
				// e.printStackTrace();
			}
		}// next i

	}// loadSurf

	// OBJECT METHODS +++ OBJECT METHODS +++ OBJECT METHODS +++ OBJECT METHODS
	/**
	 * Gets name of object
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * Gets url of object
	 */
	public String getUrl() {
		return this.url;
	}

	/**
	 * Gets data of object
	 */
	public String getData() {
		return this.data;
	}

	/**
	 * Gets texture of object
	 */
	public String getTexture() {
		return this.texture;
	}

	/**
	 * Gets number of children of object
	 */
	public int getChildCount() {
		return this.numkids;
	}

	/**
	 * Gets Texture RepeatX of object
	 */
	public float getTexRepX() {
		return this.texrepX;
	}

	/**
	 * Gets Texture RepeatY of object
	 */
	public float getTexRepY() {
		return this.texrepY;
	}

	/*
	 * The object own drawing function. Called from the renderer to redraw this
	 * instance with possible changes in values.
	 * 
	 * @param gl - The GL Context
	 * 
	 * @param filter - Which texture filter to be used
	 */
	public void draw(GL10 gl, int filter) {

		// NOTE ALL NORMALS CODE COMMENTED OUT, UNTIL I PROGRAM NORMAL
		// CALCULATOR

		/*
		 * THIS LINE DOESN'T WORK, this.texture.equals("none") always is false,
		 * yet on line 428 it works perfectly... P.S: this area is kind of messy
		 * with the multiple if conditions, but this is a work in progress and I
		 * can fix that later
		 */
		// Bind the texture according to the set texture filter
		if (!this.texture.equals("none"))
			gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);

		// Enable the vertex, texture and normal state
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		if (!this.texture.equals("none"))
			gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
		// gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

		// Set the face rotation
		gl.glFrontFace(GL10.GL_CCW);

		// Point to our buffers
		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
		if (!this.texture.equals("none"))
			gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
		// gl.glNormalPointer(GL10.GL_FLOAT, 0, normalBuffer);

		// Draw the vertices as triangles, based on the Index Buffer information
		gl.glDrawElements(GL10.GL_TRIANGLES, faces.length,
				GL10.GL_UNSIGNED_SHORT, indexBuffer);

		// Disable the client state before leaving
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
		if (!this.texture.equals("none"))
			gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
		// gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);

		// loop to draw kids!
		if (this.numkids > 0)
			for (int i = 0; i < this.numkids; i++)
				kids.get(i).draw(gl, filter);
	}

	/**
	 * Load the textures
	 * 
	 * @param gl
	 *            - The GL Context
	 * @param context
	 *            - The Activity context
	 */
	public void loadGLTexture(GL10 gl, Context context) {

		if (this.texture.equals("none")) {
			Log.i("AcLoader", ">>>> NO TEXTURE TO LOAD");
			return;
		} else
			Log.i("AcLoader", ">>>> LOADING TEX: " + this.texture);

		// Get the texture from the Android resource directory
		// InputStream is =
		// context.getResources().openRawResource(R.drawable.forty);

		Log.i("AcLoader", ">>>> ATTEMPTING TO GET RESOURCE ID FOR: |"
				+ this.texture + "|");
		int imageResource = context.getResources().getIdentifier(this.texture,
				"drawable", context.getPackageName());
		Log.i("AcLoader", ">>>> ID FOUND: " + imageResource);
		// Log.i("AcLoader", ">>>> ACTUAL ID:" + R.drawable.forty);

		InputStream is = context.getResources().openRawResource(imageResource);

		// InputStream bg = context.getResources().openRawResource(id))
		Bitmap bitmap = null;
		try {
			// BitmapFactory is an Android graphics utility for images
			bitmap = BitmapFactory.decodeStream(is);

		} finally {
			// Always clear and close
			try {
				is.close();
				is = null;
			} catch (IOException e) {
			}
		}

		// Generate there texture pointer
		gl.glGenTextures(3, textures, 0);

		// Create Nearest Filtered Texture and bind it to texture 0
		gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
				GL10.GL_NEAREST);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
				GL10.GL_NEAREST);
		GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

		// Create Linear Filtered Texture and bind it to texture 1
		gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
				GL10.GL_LINEAR);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
				GL10.GL_LINEAR);
		GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

		// Create mipmapped textures and bind it to texture 2
		gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[2]);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
				GL10.GL_LINEAR);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
				GL10.GL_LINEAR_MIPMAP_NEAREST);
		/*
		 * This is a change to the original tutorial, as buildMipMap does not
		 * exist anymore in the Android SDK.
		 * 
		 * We check if the GL context is version 1.1 and generate MipMaps by
		 * flag. Otherwise we call our own buildMipMap implementation
		 */
		if (gl instanceof GL11) {
			gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP,
					GL11.GL_TRUE);
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

			//
		} else {
			buildMipmap(gl, bitmap);
		}

		// Clean up
		bitmap.recycle();
	}

	/**
	 * Our own MipMap generation implementation. Scale the original bitmap down,
	 * always by factor two, and set it as new mipmap level.
	 * 
	 * Thanks to Mike Miller (with minor changes)!
	 * 
	 * @param gl
	 *            - The GL Context
	 * @param bitmap
	 *            - The bitmap to mipmap
	 */
	private void buildMipmap(GL10 gl, Bitmap bitmap) {
		//
		int level = 0;
		//
		int height = bitmap.getHeight();
		int width = bitmap.getWidth();

		//
		while (height >= 1 || width >= 1) {
			// First of all, generate the texture from our bitmap and set it to
			// the according level
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);

			//
			if (height == 1 || width == 1) {
				break;
			}

			// Increase the mipmap level
			level++;

			//
			height /= 2;
			width /= 2;
			Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height,
					true);

			// Clean up
			bitmap.recycle();
			bitmap = bitmap2;
		}
	}

}// class AcObject

Was This Post Helpful? 0
  • +
  • -

#5 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: .equals is broken ... not working as expected

Posted 29 November 2010 - 09:50 AM

Are you trying to compare 2 Strings? Is so you need to use .equalsIgnoreCase();
Was This Post Helpful? 0
  • +
  • -

#6 geem42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-March 08

Re: .equals is broken ... not working as expected

Posted 29 November 2010 - 10:41 AM

View PostH3R3T1C, on 29 November 2010 - 08:50 AM, said:

Are you trying to compare 2 Strings? Is so you need to use .equalsIgnoreCase();


I am trying to compare strings, but the case is the same.

note that in my original post, in the loadGlTextures method .equals DOES work, but it doesn't in the draw method
Was This Post Helpful? 0
  • +
  • -

#7 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: .equals is broken ... not working as expected

Posted 29 November 2010 - 11:10 AM

What does this show you:


...
public void draw(GL10 gl, int filter) {
    // NOTE ALL NORMALS CODE COMMENTED OUT, UNTIL I PROGRAM NORMAL
    // CALCULATOR

    /*
     * THIS LINE DOESN'T WORK, this.texture.equals("none") always is false,
     * yet on line 428 it works perfectly... P.S: this area is kind of messy
     * with the multiple if conditions, but this is a work in progress and I
     * can fix that later
     */
    Log.i("AcLoader", ">>>> In Draw(): this.texture = " 
            + this.texture 
            + ", Length = " 
            + this.texture.length());
    // Bind the texture according to the set texture filter
    if (!this.texture.trim().equals("none")) { // added .trim()
...


This post has been edited by n8wxs: 29 November 2010 - 11:11 AM

Was This Post Helpful? 0
  • +
  • -

#8 geem42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-March 08

Re: .equals is broken ... not working as expected

Posted 29 November 2010 - 06:06 PM

View Postn8wxs, on 29 November 2010 - 10:10 AM, said:

What does this show you:


...
public void draw(GL10 gl, int filter) {
    // NOTE ALL NORMALS CODE COMMENTED OUT, UNTIL I PROGRAM NORMAL
    // CALCULATOR

    /*
     * THIS LINE DOESN'T WORK, this.texture.equals("none") always is false,
     * yet on line 428 it works perfectly... P.S: this area is kind of messy
     * with the multiple if conditions, but this is a work in progress and I
     * can fix that later
     */
    Log.i("AcLoader", ">>>> In Draw(): this.texture = " 
            + this.texture 
            + ", Length = " 
            + this.texture.length());
    // Bind the texture according to the set texture filter
    if (!this.texture.trim().equals("none")) { // added .trim()
...



Thanks for the help, but so far no luck, the log displays this:

11-29 16:55:53.951: INFO/AcLoader(765): >>>> In Draw(): this.texture = none, Length = 4


clearly the length is correct, the word is correct, and the trim didn't seem to help either...

SO WEIRD


As you can see from the images:

The only texture it SHOULD have ("droideye") loads, and the rest are ignored. This proves that .equals works when glLoadTexture is called.
Posted Image

But when it comes time to draw...
Posted Image

What the heck changes?
:helpsmilie:

Thanks for your patients,
-Greg

This post has been edited by geem42: 29 November 2010 - 06:09 PM

Was This Post Helpful? 0
  • +
  • -

#9 geem42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-March 08

Re: .equals is broken ... not working as expected

Posted 29 November 2010 - 06:48 PM

Okay so it works now (thanks to n8wxs!) BUT the original condition still exists for different reasons.
Allow me to explain...

If you look at the code for the draw method, it should only use textures, if there is a texture available. Otherwise, it should just display polygons with no texture (I was planning on implementing colors / materials later)

I rewrote the Draw method to be a little clearer.
As it turns out, the .equals IS working now, but the OpenGL ES still displays the textures. Because these triangles are are untextured surfaces, all their UV coordinates are 0, 0. This means OpenGL tries to sample from one 0-width, 0-height pixel from the corner of the texture image, and stretch it over the entire polygon (triangle). OpenGL doesn't expect all corners to overlap on 0,0 so it goes haywire and textures start flickering everywhere, even though textures should only be displayed if they are available.

It should display solid white if there is no texture, as I never actually set the GL color. For whatever reason, its still drawing the only-loaded texture over all polygons that have no texture, causing a really weird tweak-out / flickery distortion on all those polygons.

It was this behavior that let me to originally think the .equals was broken, even after n8wxs's help... it's still drawing textures when I DON'T call
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
.

I'm guessing there might be an OpenGL ES error somewhere on my part? Here's the updated Draw method, the rest of the code has not changed from up above

public void draw(GL10 gl, int filter) {
    // NOTE ALL NORMALS CODE COMMENTED OUT, UNTIL I PROGRAM NORMAL CALCULATOR
	
	    
	// Bind the texture according to the set texture filter
	if (!this.texture.trim().equals("none")) { // added .trim()
		
		Log.i("AcLoader", ">>>> In Draw(): this.texture = " 
	            + this.texture 
	            + ", Length = " 
	            + this.texture.length());
		
		gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);
		gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
		gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
	}else{
		
		//added this line of code to explicitly tell it to NOT use textures
		gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
	}

		

	// Enable the vertex
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	// gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

	// Set the face rotation
	gl.glFrontFace(GL10.GL_CCW);

	// Point to our buffers
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
	// gl.glNormalPointer(GL10.GL_FLOAT, 0, normalBuffer);

	// Draw the vertices as triangles, based on the Index Buffer information
	gl.glDrawElements(GL10.GL_TRIANGLES, (this.numsurf*3), GL10.GL_UNSIGNED_SHORT, indexBuffer);

	// Disable the client state before leaving
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	// gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
	if (!this.texture.trim().equals("none"))
		gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
	
	
	

	// loop to draw kids!
	if (this.numkids > 0)
		for (int i = 0; i < this.numkids; i++)
			kids.get(i).draw(gl, filter);
}

This post has been edited by geem42: 29 November 2010 - 06:52 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1