Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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  
  ported kev's TextureLoader  (Read 2614 times)
0 Members and 1 Guest are viewing this topic.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Posted 2004-05-01 15:24:01 »

showsrc.com beautified
http://showsrc.com/$http://people.freenet.de/ki_onyx/Texture.java
http://showsrc.com/$http://people.freenet.de/ki_onyx/TextureLoader.java

plain source
Texture.java
TextureLoader.java

I hadn't much luck with JCD's loaders... and since I liked the concept of Kev's loader pretty much, I just ported it Smiley

1  
2  
3  
4  
5  
TextureLoader textureLoader = new TextureLoader();
Texture fontTexture = textureLoader.getTexture("font","data/font.png");
[...]
for binding it just call:
fontTexture.bind();


I just thought I should post it before someone else reinvents the wheel Wink

edit: bad bad board Angry

弾幕 ☆ @mahonnaiseblog
Offline karatemarkel

Junior Member





« Reply #1 - Posted 2004-05-01 16:01:54 »

Cool oNyx, I'll take a look at this as soon as I get some time. I really like JCD's texture loader though, very easy to use imo.

What problems have you had with it?

There is one thing that's puzzling me about JCD's texture loader though, but I'm not sure if it's something I'm doing or something in the code. Every time I load and display a texture it's always displayed upside down. I'm pretty sure its something I'm not setting up right on the texture loading side of things, but I've only glanced through the texture chapter of the red book so I can't be sure.

Anyone got any clues?
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #2 - Posted 2004-05-01 16:07:23 »

> What problems have you had with it?

It bombed out at GLU.gluBuild2DMipmaps IIRC

> Anyone got any clues?

Well, opengl stores them upside down. Therefore you have to flip it. See here:

http://showsrc.com/$http://people.freenet.de/ki_onyx/TextureLoader.java#215

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline karatemarkel

Junior Member





« Reply #3 - Posted 2004-05-01 16:36:23 »

>It bombed out at GLU.gluBuild2DMipmaps IIRC

JCD's worked fine for me, but as I said I've only glanced through the texture chapter, maybe JCD can shed some light.

>Well, opengl stores them upside down.

That I didn't know, I've just been flipping them in photoshop to solve the issue Smiley
I'll really have to read that red book properly sometime.

Cheers Smiley
Offline Java Cool Dude

Senior Member




Java forever


« Reply #4 - Posted 2004-05-01 16:48:03 »

Hmmm I've updated my texture loader few days ago with an option to flip the images upside down.
I also corrected a bug where a texture is declared BGR while it's clearly RGB.
Check it out in my work frame Tongue
Offline tom
« Reply #5 - Posted 2004-05-01 16:56:51 »

Quote
There is one thing that's puzzling me about JCD's texture loader though, but I'm not sure if it's something I'm doing or something in the code. Every time I load and display a texture it's always displayed upside down.

Tga files can have it's image stored upside down. Last time I checked, JCD loader don't check the upside down flag in the tga header. So wich way is up is determined by the program that made the file. PSP and adobe photoshop stores the images in different ways. (btw the flag is the 5th bit of the imageDescriptor field)

Quote
It bombed out at GLU.gluBuild2DMipmaps IIRC

This sounds like a bug in JCD image loader. It will fail when using non power of two texture that do not match opengls unpack alignment. UNPACK_ALIGNMENT must be set to to 1 before calling GLU.gluBuild2DMipmaps or it can throw a IndexOutOfBoundsException.

There is also a bug in gluBuild2DMipmaps wich causes non power of two texture to have stripes.

Kevs texture loader don't have any of these problems because he converts the images to pow two before they are sent to opengl

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #6 - Posted 2004-05-01 17:12:55 »

Quote
Hmmm I've updated my texture loader few days ago with an option to flip the images upside down.
I also corrected a bug where a texture is declared BGR while it's clearly RGB.
Check it out in my work frame Tongue


Good to know.

I'll keep it in mind for the case, that I ever need a AWT free version Wink

edit: oh... I used power of 2 PNGs (24 and 32 bit)

弾幕 ☆ @mahonnaiseblog
Offline M4g3

Senior Newbie




Java games rock!


« Reply #7 - Posted 2004-05-05 17:56:19 »

I'm trying to use your code to get lwjgl to display a 2d png image on the screen, however I'm a bit stuck


in my init I have
1  
2  
TextureLoader textureLoader = new TextureLoader(); 
Texture fontTexture = textureLoader.getTexture("font","data/test.png");


I also declared fontTexture at the top using:
1  
private static Texture fontTexture; 


then in my render part I have:
1  
fontTexture.bind();


everything works fine when I leave the bind() part out, but when I put it in I get the following output:

Loading texture data/test.png to ID: 1 wrap:true mipmapped:false
java.lang.NullPointerException
       at org.lwjgl.examples.Game.render(Game.java:170)
       at org.lwjgl.examples.Game.run(Game.java:115)
       at org.lwjgl.examples.Game.main(Game.java:45)
Press any key to continue...

This should probably go into the Clueless Newbie section, because my main question is of course how the hell do I get a 2d sprite on the screen using lwjgl. I figured on the texture loading, I've done the first 5 nehe tutorials with success. I had a look at the Space Invaders 103 tutorial. But I can't get it to work Sad So I guess I'm clueless, but I'm just missing something.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #8 - Posted 2004-05-05 18:23:52 »

It looks like you've declared fontTexture twice - the first class member one gets hidden by the second local one you declare (and assign to) in your init. Remove your duplicate 'Texture' delclaration in the init method.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Morgrog

Senior Newbie




Rubber bands and cafeine, weeeee~


« Reply #9 - Posted 2004-05-05 18:54:52 »

Noob question inc  Huh

What image formats are supported by awt's BufferedImage?

I'm gonna use this purrrty textureloader as soon as I find textures to load  Grin


edit: added a 's' to formats Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline M4g3

Senior Newbie




Java games rock!


« Reply #10 - Posted 2004-05-05 19:55:30 »

thanks for the help, I got the texture on a cube now!  Shocked Grin

*celebrates*
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #11 - Posted 2004-05-05 20:32:21 »

> What image formats are supported by awt's BufferedImage?

All Smiley

The question is wich formats does ImageIO support.

Quote
static String[]       getReaderFormatNames()
Returns an array of Strings listing all of the informal format names understood by the current set of registered readers.


---

Oh and one thing I've to add:

If you setup the perspective by yourself you don't necessarly need to flip the textures.

e.g.
GLU.gluOrtho2D(0, Window.getWidth(), Window.getHeight(), 0);

Then 0,0 is in the upper left and textures doesnt need to be flipped. However, it will break alot of things (eg text printing methods).

You could also flip the image once by yourself. Well, I guess I'll just continue flipping in the loader... and once I'm done, I'll use a little programm to flip all images and then I'll just remove the flip part. I know some commercial games wich just did that and I have to admit it's the most painless way Wink

弾幕 ☆ @mahonnaiseblog
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #12 - Posted 2004-05-05 21:29:31 »

A Wise Bunny will flip the texture coordinates, not the projection Wink

Cas Smiley

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #13 - Posted 2004-05-05 22:41:29 »

> A Wise Bunny will flip the texture coordinates, not the projection Wink

Of corse. Well, in my case it's a major headache and since I'll need a post processing stage anyways (pngout) I can just flip 'em aswell.

But then again... I guess there is an easy way to flip the coords (eg just writing a method wich calls glTexCoord2f with flipped coords) or maybe there is an ogl way to do it? :>

弾幕 ☆ @mahonnaiseblog
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #14 - Posted 2004-05-05 23:05:41 »

Quote
But then again... I guess there is an easy way to flip the coords (eg just writing a method wich calls glTexCoord2f with flipped coords) or maybe there is an ogl way to do it? :>

You could probably set the texture coord matrix to flip on the y axis (-1 y scale) but thats likely to cause problems if you ever tried to use tex coord generation etc.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #15 - Posted 2004-05-06 00:21:09 »

Hmhmhm ok.

I say yes to post processing Tongue Grin

弾幕 ☆ @mahonnaiseblog
Offline M4g3

Senior Newbie




Java games rock!


« Reply #16 - Posted 2004-05-12 21:37:20 »

I'm really in need of some help on getting alpha channels/png's with transparency to work.

I would like to have png's in some transparent form, but I have no idea what the problem is, I tried almost all options in formats but I'm either getting a NullPointer error which stops the game from running, or my texture is colored black (the background color) instead of being transparent, I'm having another texture moving behind the transparent one. Could anyone give me some pointers? or do I need to dive into blending/masks instead of just using the textureloader from this topic?
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #17 - Posted 2004-05-12 21:57:26 »

Quote

or do I need to dive into blending/masks instead of just using the textureloader from this topic?

A texture/file loader will only get you part of the way there - actually importing the image data into a texture. At this point all you'll have is a texture with RGBA data, you have to tell OpenGL how you want it to use the alpha data to draw the texture.

Simplest weighted-average type blending is:
glEnable(GL.GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBlendFunc(GL_SRC_ALPHA, GL_ONE) gets you additive blending, which is what you want if you're doing some particle type effects.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline M4g3

Senior Newbie




Java games rock!


« Reply #18 - Posted 2004-05-13 13:00:57 »

I got it now, I was just unsure about whether the textureloader was already doing transparency because of .hasAlpha() stuff in it. But the way you showed it works perfect, and I also know where to look now if I want more. So thanks! Smiley
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #19 - Posted 2004-05-13 13:27:11 »

>because of .hasAlpha() stuff in it

hasAlpha() is used to (surprise) determine if the image has an alpha channel or not. If so, RGBA is used otherwise RGB (in order to avoid the wasting of valuable vram) Smiley

弾幕 ☆ @mahonnaiseblog
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #20 - Posted 2004-05-13 18:37:28 »

Again the fruitful code snippets of the lwgjl group is overwhelming.  Playing with the ported loaders (luv Kev's code anyway), and getting a BufferOverflowException for a 1 k gif.  I created Textrue Loader, Texter from loader then a bind in my render.  (not really sure what to bind it to, if you even do that)  Want to put the image on a quad.

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
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.

CogWheelz (17 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
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!