Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Textures in LWJGL  (Read 2890 times)
0 Members and 1 Guest are viewing this topic.
Offline Harley Rana

Junior Devvie




Java games rock!


« Posted 2002-12-29 01:27:13 »

Hey im having some problems getting texture loading to work.  
Im loading the texture data with bufferedImage.getData().getPixels(0,0, width,height,pixels);

How do i call glGenTextures when it takes (int,int)instead of (int,int[]), as in gl4Java?

What is the correct method for loading textures in LWJGL?

Thanks heaps!  Harley Smiley
Offline elias

Senior Devvie





« Reply #1 - Posted 2002-12-29 09:02:06 »

*everything* in lwjgl not ordinary parameters like floats, int etc. are direct buffers of some kind, including write back parameters from GL.

So to make genTextures work, you'd have to do something like:
1  
2  
3  
4  
5  
6  
7  
        ByteBuffer buf = ByteBuffer.allocateDirect(4);
        buf.order(ByteOrder.nativeOrder());
        IntBuffer int_buf = buf.asIntBuffer();
        GL.genTextures(1, Sys.getDirectBufferAddress(int_buf));
        if (int_buf.buffer().get(0) == 0)
               throw new RuntimeException("Could not allocate new texture id!");
        return int_buf.get(0);

Likewise, when you want to upload pixel data into a GL texture, it has to be in a buffer and given as an address to GL through Sys.getDirectBufferAddress(..).

It might seem overly complicated, but it really is a the fastest way to call GL, that is using explicit C pointers.

Sys.getDirectBufferAddress() returns the int pointer address of a direct buffer (DON'T use a non-direct buffer), and thats' why for every gl function taking an array or simply a pointer, an int is taken by lwjgl.

Don't scare yourself because of this, lwjgl is really a slick binding, and almost every user of it (I believe) simply encapsulates the behaviour in utility classes.

The lwjgl author also released spgl (also on sourceforge) that sits on top of lwjgl and exposes more friendly behaviour.

- elias

Offline Exocet

Senior Newbie





« Reply #2 - Posted 2003-01-02 19:03:47 »

Any thoughts on creating a single texture generating func ?  such as gen1Texture()... so you don't have to deal with the byte buffers if you don't want to.  But then again... why would you want only 1 texture?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elias

Senior Devvie





« Reply #3 - Posted 2003-01-02 19:22:25 »

I never saw the use for generating multiple texture handles at the same time. I always end up allocating them one after another - I see no use for consecutive texture handles.

Anyway, lwjgl is designed with simplicity and speed in mind. Therefore it's easy to get the "talking to a device driver" feeling with it, but that's intentional. lwjgl makes no attempt to be user friendly if that would make the layer between e.g. opengl and you any thicker. And that's why lwjgl will never include utility/helper functions like the one you mentioned. The Shaven Puppy Game Library by the same author is built ont top of lwjgl and tries to do just that.

- elias
- elias

Offline Exocet

Senior Newbie





« Reply #4 - Posted 2003-01-04 18:41:28 »

true.. but there are cases such as this where it is just more efficient to do it JNI

1  
2  
3  
GLuint texture;
glGenTextures(1, &texture);
return (jint) texture;


as opposed to the 4 byte, bytebuffer that would have to be generated then disposed of for the same effect within java.

- Tristan
Offline elias

Senior Devvie





« Reply #5 - Posted 2003-01-04 19:23:22 »

Nah, the utility class just holds one reference to a static 'result' buffer, and never release it.

- elias

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.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (60 views)
2014-12-09 22:41:13

BurntPizza (95 views)
2014-12-08 04:46:31

JscottyBieshaar (55 views)
2014-12-05 12:39:02

SHC (71 views)
2014-12-03 16:27:13

CopyableCougar4 (73 views)
2014-11-29 21:32:03

toopeicgaming1999 (133 views)
2014-11-26 15:22:04

toopeicgaming1999 (124 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!