Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] LWJGL - Draw section of texture  (Read 855 times)
0 Members and 1 Guest are viewing this topic.
Offline pwnedary

Senior Newbie





« Posted 2013-05-10 08:43:59 »

I'm new to LWJGL, and wonder how to draw a section of an image for example a spritesheet, in a 2d game. I have been browsing the internet and only found that you can have half numbers to
1  
glTexCoord2f(0.5f, 0.5f);
.
Also does the textures dimensions need to be the power of 2, and can you draw a part 12x14 in dimensions of a texture.

Thanks in advance.
Offline NegativeZero

JGO Knight


Medals: 30
Projects: 2
Exp: 3 years


Zero but not.


« Reply #1 - Posted 2013-05-10 08:49:22 »

You need the height/width of the sheet, the height/width of each image and which image you want.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
glTexCoord2f(                                                 //  0 0
   1/sheetWidth * whichImageX,
    1/sheetHeight * whichImageY);
glTexCoord2f(                                                 //  1 0
   1/sheetWidth * whichImageX + imageWidth,
    1/sheetHeight * whichImageY);
glTexCoord2f(                                                 //  1 1
   1/sheetWidth * whichImageX + imageWidth,
    1/sheetHeight * whichImageY + imageHeight);
glTexCoord2f(                                                 //  0 1
   1/sheetWidth * whichImageX,
    1/sheetHeight * whichImageY + imageHeight);
Offline quew8

JGO Coder


Medals: 29



« Reply #2 - Posted 2013-05-10 16:16:02 »

Some hardware can handle non-power of two (pot) texture dimensions, some cannot. You can check but this would mean you would need to have two versions of each texture and it is an effort so frankly, when you can stitch several npot images into 1 pot texture and scale like there's no tomorrow, what is the point?

NB. I think that a lot of hardware that does support it would suffer at least a slight performance drop do again, what is the point?

NB2 Be careful with OpenGL texture y-coords. 0 is the top of the texture and 1 is the bottom. Not friendly but convention is older than time itself (no it's just OpenGL messing with you)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-05-10 19:07:46 »

All of this and more should be explained in my Textures tutorial:
https://github.com/mattdesl/lwjgl-basics/wiki/Textures

Let me know if you have more questions. Smiley

Offline jhffvcc

Senior Newbie







« Reply #4 - Posted 2013-05-10 19:28:14 »

glTexCoord2f is deprecated, isn't it?

Why you don't try learning 'modern' OpenGL? And why so many others just still continue using the static pipeline? I think OpenGL 3.x is worth learning it.
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #5 - Posted 2013-05-10 22:49:18 »

glTexCoord2f is deprecated, isn't it?

Why you don't try learning 'modern' OpenGL? And why so many others just still continue using the static pipeline? I think OpenGL 3.x is worth learning it.

OpenGL 3.x isn't supported enough yet.

OpenGL 2.x is currently the best target.

Offline jhffvcc

Senior Newbie







« Reply #6 - Posted 2013-05-10 23:07:36 »

glTexCoord2f is deprecated, isn't it?

Why you don't try learning 'modern' OpenGL? And why so many others just still continue using the static pipeline? I think OpenGL 3.x is worth learning it.

OpenGL 3.x isn't supported enough yet.

OpenGL 2.x is currently the best target.

Maybe the best target for compatibility reasons, but for high performance OpenGL 3.x or above is needed! In my mind OpenGL =< 2.x is only good for small scenes or so called demos, to show a part of something...
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #7 - Posted 2013-05-10 23:15:51 »

You do realise OpenGL 2.x has VBOs, Shaders, FBOs etc. right?

The only notable upgrades in 3.x are VAOs and in/out shaders. (and FBOs added to the core)

Guardian II uses OpenGL 2.x

Offline davedes
« Reply #8 - Posted 2013-05-11 02:40:30 »

FBOs are supported in 93% of cards. If the card supports shaders, it most likely supports FBOs. VAOs are supported in at least 84% of cards.

http://feedback.wildfiregames.com/report/opengl/

Quote
but for high performance OpenGL 3.x or above is needed
Not at all true...

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #9 - Posted 2013-05-11 02:56:31 »

jhffvcc already PM'd me and we had a discussion on OpenGL 2.x and 3.x

I think he got my point about OpenGL 2.x still being 'modern'.

Even more off topic:

Despite OpenGL 2.x supposedly being supported on 93% or cards, of the 7* people that wanted to test Guardian II, 2 of them only had graphics cards supporting OpenGL 1.4  Undecided

(*7 people that actually responded. 2 never got back to me.)

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline relminator
« Reply #10 - Posted 2013-05-11 06:07:59 »

I have 3 laptops I use constantly and they don't even support 2.x.

My 2.x compatible desktop died due to air saltiness from where I live.

The only way I could do shaders nowadays is from my droid phone which sadly drains a lot of battery and heats the crap out off my phone.


What's wrong with learning both pipelines?
Offline theagentd
« Reply #11 - Posted 2013-05-11 09:10:39 »

The only notable upgrades in 3.x are VAOs and in/out shaders. (and FBOs added to the core)
And instancing and geometry shaders and non-matching FBO attachments and 32-bit float texture filtering support.

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!