Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
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  
  mipmap problems  (Read 1582 times)
0 Members and 1 Guest are viewing this topic.
Offline Rob Nugent

Junior Member




May contain nuts


« Posted 2003-08-01 10:36:13 »

Hi All,

I'm seeing my mipmapped textures corrupted with unexpected colours (usually bright red). The corruption seems to be occuring in the
2x2 or possibly 1x1 mipmap levels. All the other levels seem OK.

This happens on both Win32 and Solaris9, so I suspect it's not a driver problem. If anyone can suggest anything wrong with my texture loading code, I'd appreciate the feedback. Note that this code is overriding all mipmap data to be white pixels, and I'm still seeing the unexpected 'red'.

If anyone can explain to me how to attach a screen grab here, I'll happily show what I'm seeing.

(Apologies for the indentation of the attached)

Code follows:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
     private void init(Texture2D t,GL gl) {
        //
       // Convert the BufferedImages to buffers that JOGL can deal with
       //
       BufferedImage[] images = t.getImages();

        buffers = new ByteBuffer[images.length];

        for (int i = 0; i < images.length; i++) {
            switch(images[i].getType()) {

                case BufferedImage.TYPE_INT_ARGB: {
                    int[] data = ((DataBufferInt)
                        images[i].getRaster().getDataBuffer()).getData();
                    buffers[i] = ByteBuffer.allocateDirect(data.length * 3);

                    byte[] b = new byte[3];
               
                    int h = images[i].getHeight();
                    int w = images[i].getWidth();

                    // We must invert the image
                   for (int y = h - 1; y >= 0; y--) {
                        for (int x = 0; x < w; x++) {
                            int index = y * w + x;
                            int val = data[index];

                            int blue  = val & 0xff;
                            int green = (val >> 8)  & 0xff;
                            int red   = (val >> 16) & 0xff;
                       
                            b[0] = (byte)red;
                            b[1] = (byte)green;
                            b[2] = (byte)blue;

                            //
                           // Debug - override the supplied data
                           // with WHITE
                           //
                           b[0] = (byte)0xff;
                            b[1] = (byte)0xff;
                            b[2] = (byte)0xff;

                            buffers[i].put(b);
                        }
                    }
                    break;
                }
 
                default:
                    System.out.println("Unsupported image type " +
                                                images[i].getType());
                    System.exit(-1);
           
            }
        }

        //
       // Allocate a texture id
       //
       textureID = createTextureID();
       
        bind(gl);

        gl.glTexParameteri(     GL.GL_TEXTURE_2D,
                                GL.GL_TEXTURE_WRAP_S,
                                GL.GL_REPEAT);

        gl.glTexParameteri(     GL.GL_TEXTURE_2D,
                                GL.GL_TEXTURE_WRAP_T,
                                GL.GL_REPEAT);

        gl.glTexParameteri(     GL.GL_TEXTURE_2D,
                                GL.GL_TEXTURE_MIN_FILTER,
                                GL.GL_LINEAR_MIPMAP_LINEAR);    // Check this
       gl.glTexParameteri(     GL.GL_TEXTURE_2D,
                                GL.GL_TEXTURE_MAG_FILTER,
                                GL.GL_LINEAR);                  // Check this

        //
       //
       //
       for (int i = 0; i < buffers.length; i++) {
            gl.glTexImage2D(GL.GL_TEXTURE_2D,
                            i,
                            GL.GL_RGB,
                            images[i].getWidth(),
                            images[i].getHeight(),
                            0,                          // border width
                           GL.GL_RGB,
                            GL.GL_UNSIGNED_BYTE,
                            buffers[i]);
        }
    }

    protected void bind(GL gl) {
        gl.glBindTexture(GL.GL_TEXTURE_2D, textureID );
    }
Offline DavidYazel

Junior Member




Java games rock!


« Reply #1 - Posted 2003-08-01 11:04:13 »

I don't have a lot of time to figure it out for sure.  But the one thing that is jumping out to me is that the buffer is ARGB which is 4 byts, not 3.  Thats unless you set up your buffered image to be backed by a sperate alpha raster, which is unlikely.

Check out my TextureLoader in the Xith3D project (com.xith3d.loaders.texture.TextureLoader) and the DirectBufferedImage in com.xith3d.image.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline Rob Nugent

Junior Member




May contain nuts


« Reply #2 - Posted 2003-08-01 11:24:35 »

David,

If might be somethig like that. The 'input' BufferedImages are all TYPE_INT_ARGB. I don't care about the alpha channel, so I'm trying to discard it and only give the RGB bits of the data to JOGL in a direct ByteBuffer where the data is laid out RGBRGBRGB... etc.

This is working nicely for all the 'large' mipmap levels 128x128,64x64,32x32 etc, but seems to break for 2x2 and/or 1x1.

If I change this to give JOGL the full RGBA data (and change the code to specify GL_RGBA) I get no corruption. I don't see why the first approach doesn't work though, and I'd prefer not to be incurring a 33% overhead on my texture storage.

Still puzzled,
Rob
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DavidYazel

Junior Member




Java games rock!


« Reply #3 - Posted 2003-08-01 11:42:24 »

If the input buffered images are ARGB then you either have to convert them to RGB or send the data to the card as ARGB.  To convert them, just create a buffered image of RGB then write into it from the other.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline DrLabman

Junior Newbie




Opengl games rock!


« Reply #4 - Posted 2003-08-01 11:50:39 »

hmm, /me looks at code again

QMB Quake Engine - http://qmb.quakepit.com
Offline Rob Nugent

Junior Member




May contain nuts


« Reply #5 - Posted 2003-08-01 11:54:06 »

David,

The code I posted is converting the TYPE_INT_ARGB BufferedImages to RGB format data in the direct ByteBuffers which are then given to JOGL.

It's taking each int from each BufferedImage, strips out the R,G and B bytes, and puts those in the ByteBuffer.

Rob
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 (24 views)
2014-08-22 19:31:30

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

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

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

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

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

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

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

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

Norakomi (42 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!