Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 5:12 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Jul 06, 2012 5:00 am 
Offline

Joined: Sat Aug 06, 2011 10:50 pm
Posts: 7
Location: United States
I'm fairly sure this has something to do with Slick and not the LWJGL, and there's also a high probability that I did something wrong... Anyways...

I'm having this weird problem when I'm drawing images to the screen, even when I'm drawing them at the resolution of the images (which are both 10x10).
pastebin link with more info: http://pastebin.com/xAAn7zqP

/me goes off to bed.


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 11:39 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
See this:
viewtopic.php?p=25911#p25911


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 6:51 pm 
Offline

Joined: Sat Aug 06, 2011 10:50 pm
Posts: 7
Location: United States
After following the advice from that code, I changed mine to do the same thing (relatively speaking):
Code:
//before
         glTexCoord2f(0f,0f);
         glVertex2f(Vertices.get(0).x, Vertices.get(0).y);
         glTexCoord2f(0f,1f);
         glVertex2f(Vertices.get(1).x, Vertices.get(1).y);
         glTexCoord2f(1f,1f);
         glVertex2f(Vertices.get(2).x, Vertices.get(2).y);
         glTexCoord2f(1f,0f);
         glVertex2f(Vertices.get(3).x, Vertices.get(3).y);
//after
         glTexCoord2f(0f,0f);
         glVertex2f(Vertices.get(0).x, Vertices.get(0).y);
         glTexCoord2f(0f,10f);
         glVertex2f(Vertices.get(1).x, Vertices.get(1).y);
         glTexCoord2f(10f,10f);
         glVertex2f(Vertices.get(2).x, Vertices.get(2).y);
         glTexCoord2f(10f,0f);
         glVertex2f(Vertices.get(3).x, Vertices.get(3).y);

Although the output is far from desired: Image


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 8:17 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Your texcoords are incorrect.

glTexCoord takes a normalized texture coordinate in UV space -- this means values between 0 and 1. (Values outside of this range result in texture stretch/repeat/mirror depending on wrap mode.)

Use myTexture.getWidth()/getHeight() to get the normalized value that would be passed to glTexCoord2f. In your case, since your image is 10x10 and it's loaded as a power of two 16x16 texture, the value would be 10 / 16 => 0.625. Refer to my earlier posted code for details. :)

I'd suggest reading up on OpenGL texturing basics before trying to continue... ;)


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 9:16 pm 
Offline

Joined: Sat Aug 06, 2011 10:50 pm
Posts: 7
Location: United States
Woah, that worked. Thanks! =D

I'll need to remember that for next time (and read up a bit more like you said).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group