Problem with Sprites and GL11-Drawing

Started by Schnitter, January 31, 2008, 11:32:11

Previous topic - Next topic

Schnitter

Hi,

I wrote a Sprite-Class(a few weeks ago...). And yesterday, I discovered an problem with my sprites: I can not draw lines/points/rectangles or whatever, after I rendered a sprite to the Screen.
There's no exception throwed, no error...It's just not visible :/
Here is the code of my sprite-class:
http://rafb.net/p/PkEI7J55.html

I draw my triangles like this:
GL11.glColor4f(0f, 0f, 0f, 1f);
			GL11.glBegin(GL11.GL_TRIANGLES);
				GL11.glVertex2i((int)pos.x-8, (int)pos.y+4);
				GL11.glVertex2i((int)pos.x+8, (int)pos.y+4);
				GL11.glVertex2i((int)pos.x, (int)pos.y-4);
				GL11.glColor4f(1f, 1f, 1f, 1f);
			GL11.glEnd();


And I discovered:
When I'm removing my glClear() from my code - I can see the triangle. And with glClear() - I discovered I can see it for a very short Time.

Just for safety - heres the code of my main-Class:
http://rafb.net/p/JEro7r45.html



I hope, you can find my error ;)



-Schnitter

ndhb

Have you tried disabling texturing after you're done rendering sprites?

Schnitter

Now, yes^^
But it doesn't work. The first problem is, that I used completely the same technic to do an other game - and it works.
I did some more tests and now I think the problem is in my Font-Class(which writes text to the screen).
My Font-Class looks like this: http://rafb.net/p/noo4XF27.html

And I can still not find the bug :(

ndhb

If it isn't a texture that's left enabled (e.g. in your font code) either - you can try and surround the offending code with

GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

<your code that prevents rendering of lines, triangles etc.>

GL11.glPopAttrib();

Then gradually narrow down the possible problem.

Good luck.

ndhb

Another unrelated thing. Writing code like:

GL11.glColor4f(0f, 0f, 0f, 1f);
GL11.glBegin(GL11.GL_TRIANGLES);
   GL11.glVertex2i((int)pos.x-8, (int)pos.y+4);
   GL11.glVertex2i((int)pos.x+8, (int)pos.y+4);
   GL11.glVertex2i((int)pos.x, (int)pos.y-4);
   GL11.glColor4f(1f, 1f, 1f, 1f);
GL11.glEnd();

Is slightly confusing to read. It sort of suggests that the statement: GL11.glColor4f(1f, 1f, 1f, 1f) has anything to do with the Triangle you draw, when it in fact doesn't. The triangle will be colored black (glColor is associated with all glVertex statements until changed). Maybe it's more clear to write:

GL11.glBegin(GL11.GL_TRIANGLES);
   GL11.glColor4f(0f, 0f, 0f, 1f); // draw the next triangle in black
   GL11.glVertex2i((int)pos.x-8, (int)pos.y+4);
   GL11.glVertex2i((int)pos.x+8, (int)pos.y+4);
   GL11.glVertex2i((int)pos.x, (int)pos.y-4);
GL11.glEnd();

GL11.glColor4f(1f, 1f, 1f, 1f); // change to white from now on

Schnitter

I tried both Ideas and it still does not want to work :(

I uploaded the complete project so you can see the complete code.
I don't want you to look through the complete code - but maybe you want to :D

And I can definitly say it now: The problem is in the Sprite-Class.
When you look into my font-class(in the package below) you can see, that I commented(Sorry - I don't know the word now :/) the whole write()-method.


(I wanted to upload it on my webspace - but it's too big for the freehoster :()
Package:http://www.megaupload.com/de/?d=W3J1Q9M2

bobjob

your drawing the sprite using two co-ordinates x, y. did you setup ortho mode first?

also add GL11.glLoadIdentity(); after the clear function just for any translations that may take place in your code.

ndhb

Okay hehe. As I wrote in the first post, you're drawing the lines with textures and they have to be disabled for the lines to look correct. What I didn't write clearly is what to do. I now looked through your code and you could write a method in your Texture class:

   public void unbind(){
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
   }

Then call tex.unbind() right before:
Font.java: line 377

and similarly texture.unbind():
Sprite.java: line 139

princec

Why not just do a glDisable(GL_TEXTURE_2D) before line drawing?

Cas :)