Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (763)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (852)
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  
  problems creating textures  (Read 3141 times)
0 Members and 1 Guest are viewing this topic.
Offline thalador

Junior Devvie


Projects: 1



« Posted 2004-08-27 18:21:20 »

Hello,

I have got problems creating a texture with lwjgl.
Here's the code:

loading data:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
tga x = new tga();
        x.load(new File("./test2.tga"));
       
        ByteBuffer f = x.getPixelData();
       
        TexBuf = BufferUtils.createIntBuffer(5);
        GL11.glGenTextures(TexBuf);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, TexBuf.get(0));
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, x.getWidth(), x.getHeight(),
                    0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, x.getPixelData()); *
       


rendering code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
         
            GL11.glPushMatrix();
            GL11.glTranslatef(0.0f, 0.0f, -12.0f );
           
            GL11.glBegin(GL11.GL_QUADS);
                  GL11.glTexCoord2f(0.0f,0.0f);
                  GL11.glVertex3f(-1.0f, -1.0f, 0.0f);
                 
                  GL11.glTexCoord2f(1.0f,0.0f);
                  GL11.glVertex3f(1.0f, -1.0f, 0.0f);
                 
                  GL11.glTexCoord2f(1.0f,1.0f);
                  GL11.glVertex3f(1.0f, 1.0f, 0.0f);
                 
                  GL11.glTexCoord2f(0.0f,1.0f);
                  GL11.glVertex3f(-1.0f, 1.0f, 0.0f);      
            GL11.glEnd();
            GL11.glPopMatrix();
         
           

The tga getPixelData Method returns a ByteBuffer with the Pixeldata. I use only 24Bit TGAs with no alphabits.
I get a java.nio.BufferOverflowException in the line marked with the *

What am I doing wrong? I can't really figure out at the moment. If you want I can post the tga-loading code, but it is really hacked together.

Greetings
thalador
Offline aldacron

JGO Coder


Medals: 20
Exp: 19 years


Java games rock!


« Reply #1 - Posted 2004-08-27 23:40:28 »

My first guess, without seeing the code for the tga loader, is that getPixels is returning a buffer which is not rewound. Make sure that the when the image is loaded the buffer is rewound.
Offline thalador

Junior Devvie


Projects: 1



« Reply #2 - Posted 2004-08-28 08:53:40 »

Hello again,

yes, that was really the problem. I forgot to rewind() the buffer. I am very new to these nio-Buffers and I start to think that they hate me :)

The next problem is already there: I can only see a white rectangle with no texture, but there should be one. First I thougth that my tga loader may be spilling out corrupt data, but the values look okay in debugger mode. Also glIsTexture returns true. So I googled a bit and they say that this happens if I call the texture functions before getting a GL-Context, but I am definetly calling the texture-functions after the whole lwjgl-window creation an d so. Another google result said, that this could happen, if the texture data is corrupt or the texture couldn't be created.
To make sure that the error is not the tga loader I created a 2x2 texture by hand:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
//another texture
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, TexBuf.get(1));
        ByteBuffer pix = BufferUtils.createByteBuffer(12);
        pix.put((byte)5); pix.put((byte)5); pix.put((byte)5);
        pix.put((byte)30); pix.put((byte)100); pix.put((byte)100);
        pix.put((byte)40); pix.put((byte)40); pix.put((byte)40);
        pix.put((byte)0); pix.put((byte)0); pix.put((byte)50);
        pix.rewind();
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 2, 2,
                    0, GL11.GL_RGB, GL11.GL_BYTE, pix);
       
        System.out.println("" + TexBuf.get(1)+" "+ GL11.glIsTexture(TexBuf.get(1)));

output is: 2 true
The drawing code is still the same, except I use TexBuf.get(1) now and there is another GL11.glBindTexture(GL11.GL_TEXTURE_2D, TexBuf.get(1)); in it. Whats wrong this time?

Greetings
thalador

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 57
Projects: 11


Monkey for a head


« Reply #3 - Posted 2004-08-28 09:13:28 »

Hmm, have you actually enabled texturing with glEnable(GL_TEXTURE_2D) ?

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

Junior Devvie


Projects: 1



« Reply #4 - Posted 2004-08-28 09:29:45 »

Yepp I did enable it
Offline thalador

Junior Devvie


Projects: 1



« Reply #5 - Posted 2004-08-28 09:54:40 »

I've uploaded the source, perhaps that helps:
GLTest.java
tga.java
test2.tga
Offline thalador

Junior Devvie


Projects: 1



« Reply #6 - Posted 2004-08-31 11:42:30 »

Hmm, can't nobody help me? I've gone through the hole forum searching for similiar problems, but I haven't found something that could help me.
Or isn't it possible to fill a ByteBuffer with a few Bytes and then pass this Buffer to glTexImage2D?
-Buffer is in native order
-Buffer is rewinded
-Buffer is direct
-Texturing is enabled
-glIsTexture returns true
-glBind is used

I can't figure it out.
Offline Middy

Junior Devvie




Java games rock!


« Reply #7 - Posted 2004-08-31 13:03:19 »

This is commented out

1  
2  
3  
4  
5  
       //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
       


When do I get my makeMyGameAsILike() extension?
Offline thalador

Junior Devvie


Projects: 1



« Reply #8 - Posted 2004-08-31 16:37:48 »

Yes, that is right, I tried it uncommented but it still doesn't work and for that parameters are used the standardvalues so it should work anyway, shouldn't it?

I thought something like that:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
byte [] b = new byte[12];
        b[0] = 23; b[1]=5; b[2]=50;
        b[3] = 0; b[4]=0; b[5]=50;
        b[6] = 50; b[7]=0; b[8]=0;
        b[9] = 23; b[10]=5; b[11]=50;
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, TexBuf.get(3));
        ByteBuffer b1 = BufferUtils.createByteBuffer(12);
        b1.put(b);
        b1.rewind();
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 2, 2, 0, GL11.GL_RGB, GL11.GL_BYTE, b1);
        System.out.println("" + TexBuf.get(3)+" "+ GL11.glIsTexture(TexBuf.get(3)));


should work in any case.

thala
Offline Middy

Junior Devvie




Java games rock!


« Reply #9 - Posted 2004-08-31 17:36:17 »

Look for the JCD utils in this forum. He has a working TGA loader Smiley

When do I get my makeMyGameAsILike() extension?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline thalador

Junior Devvie


Projects: 1



« Reply #10 - Posted 2004-08-31 19:39:58 »

Well I think it works finally, I had a ByteBuffer with ByteOrder.LITTLE_ENDIAN which I copied into one with ByteOrder.nativeOrder(). Damn it that hurts Smiley

But why my above example doesn't work I still don't know, but it doesn't matter, my tga-loader works.

The Code from Java Cool Dude is an interesting piece of Code for a newb like me Smiley

Thanks to you all
Thala
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (492 views)
2018-06-10 19:43:48

EgonOlsen (595 views)
2018-06-10 19:43:44

EgonOlsen (406 views)
2018-06-10 19:43:20

DesertCoockie (743 views)
2018-05-13 18:23:11

nelsongames (1016 views)
2018-04-24 18:15:36

nelsongames (981 views)
2018-04-24 18:14:32

ivj94 (1545 views)
2018-03-24 14:47:39

ivj94 (557 views)
2018-03-24 14:46:31

ivj94 (1295 views)
2018-03-24 14:43:53

Solater (560 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!