Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
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 3257 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:
        ByteBuffer buf = ByteBuffer.allocateDirect(4);
        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

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.

Dwinin (70 views)
2015-11-07 13:29:08

Rems19 (80 views)
2015-10-31 01:36:56

Rems19 (72 views)
2015-10-31 01:32:37

williamwoles (106 views)
2015-10-23 10:42:59

williamwoles (92 views)
2015-10-23 10:42:45

Jervac_ (106 views)
2015-10-18 23:29:12

DarkCart (134 views)
2015-10-16 00:58:11

KaiHH (116 views)
2015-10-11 14:10:14

KaiHH (155 views)
2015-10-11 13:26:18

BurntPizza (169 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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‑
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!