translate

Is there some particular reason 0 is the bottom of the screen for a y translation? Or is that just how things work in 3d? I’m drawing some tiles but I have to do

gl.translatef(
widthIteratortileSize
(screenHeight-tileSize)+(heightIterator
tileSize)
0.0f );

otherwise it draws from the bottom up. :stuck_out_tongue: I guess this just seems wierd to me after doing java2d stuff for so long.

                    gl.begin( GL.QUADS );
                    gl.texCoord2f( 0.0f, 0.0f ); gl.vertex2f( 0.0f, 0.0f );
                    gl.texCoord2f( 1.0f, 0.0f ); gl.vertex2f( 16.0f, 0.0f );
                    gl.texCoord2f( 1.0f, 1.0f ); gl.vertex2f( 16.0f, 16.0f );
                    gl.texCoord2f( 0.0f, 1.0f ); gl.vertex2f( 0.0f, 16.0f );
                    gl.end();

So the first vertex2f is acually the lower left? For some reason that just seems ODD.

Though I guess I could always draw my tiles from the bottom of the visible map anyways. It’s hard to me to change my ways damnit. :stuck_out_tongue:

Ok I’m done bitching. :wink:

OpenGL doesn’t know or care where you put your origin - but the default is (x,y) at the bottom left as you mention. To flip it, you’ll need to set the modelview matrix accordingly before you draw anything. Off the top of my head it’d be a -1 scale of the y axis and translate your camera accordingly. You may be able to set this more conviniently by tinkering with the projection matrix in a similar way, but the math escapes me at the moment.

Coolbeans, I’ll look into that later.

Right now for one reason or another having the SpriteEngine(spgl) render() after drawing my tiles just makes everything go white. Things going wrong is an experience not wholly unfamiliar to me. :stuck_out_tongue_winking_eye: All I can see the sprite engine doing is putting some crap in some vertex arrays and drawing, so I dunno.

Still figuring this crap out, just slowly. Really, really slowly.

I assume you mean your textures become white? Thats usually an indication that you’ve got an invalid or unexpected texture state/setup. As a quick fix you might try a couple of pushAttrib and popAttrib around the code that breaks your tile drawing, other than that check you’re resetting texture states before you draw each frame.

gl.enable( GL.TEXTURE_2D );
gl.matrixMode( GL.PROJECTION );
gl.loadIdentity();
gl.glu.ortho2D( 0, width, 0, height );
gl.scalef( 1, -1, 1 );
gl.translatef( 0, -height, 0 );
gl.matrixMode( GL.MODELVIEW );
gl.loadIdentity();
gl.viewport( 0, 0, width, height );

This seems to work.

Edit: ya I was missing something, so now the tiles show but the sprite doesn’t. Smells like progress though, thanks. :wink:

So what could cause something to not show up? I’m still thinking far too much in 2d but, right now it’s not doing anything super funky, if I comment out my tile drawing code, the sprite shows up, but when I draw my tiles and then the sprite, it doesn’t show up on top? Is there something I’m not doing here?

Well mabey since I almost fell asleep at the keys writing that, I should just go to sleep and worry about it when I wake up. :stuck_out_tongue:

You are aware of the fact that translations etc. are cumulative? That is, remember to do a loadIdentity() before drawing each element.

  • elias

ya. I just got up so I’ll dig around a bit.

edit: ew, well, now that you mention it, that fixed my problem… For whatever reason I guess I assumed it was resetting to draw the sprites. Cas is using vertex arrays in there so I’m acually not entirely sure whats going on in terms of translation. Though looking at it now it doesn’t seem even half as complex as it did 3 days ago, so I guess I just need to dig in now.

Thanks guys, I think I might be ok for a few days. (lies) :wink:

Haha! Now I’ve just gone and tweaked all the sprite code anyway :slight_smile:

New addition: there’s a ticks-per-frame thing gone into the sprite engine. I was calling tick() on every sprite twice per frame instead of just telling the sprite engine that 2 ticks should pass for every call to tick(). Should improve performance a shade on those ol’ celerons at 30Hz.

Texture packer tool has changed a bit too, with a way to exclude directories from the list of pngs that it loads, and a way to specify what renderer is used for a particular spriteimage.

Cas :slight_smile:

evil. :wink: