Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Basic Textures In JOGl  (Read 7541 times)
0 Members and 1 Guest are viewing this topic.
Offline Antilles58

Senior Newbie





« Reply #30 - Posted 2005-12-13 04:07:55 »

I read through this thread again and saw that some people had problems with corrupted files and the like, so what I tried doing was loading in another image that we use in our program which I know works for sure, just so that I could ensure that the problem was in fact with the image I was creating rather than with the code.  However, its still broken.  I still get the black square.  I know for sure the image I've loaded is not corrupt, since it appears elsewhere in my program (in a part that isn't affected by anything JOGL-related).  Somehow something else is going wrong here.  Here is the code that creates/calls the GLdraw functions:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public void init(GLAutoDrawable gld) {

      gld.setGL(new DebugGL(gld.getGL()));
      gld.getGL().glClearColor(1.0f,1.0f,1.0f,0.5f);
   
   } // init()
 
   public void display(GLAutoDrawable gld) {
   
      GL gl = gld.getGL();
     
      setCamera(gl);
     
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
      gl.glEnable(GL.GL_POLYGON_SMOOTH);
     
      glDraw(gl);
     
      TextObject text = new TextObject(new Point2D.Double(1,1),"Hello",(Plot2DPanel)this,Color.black, new Font("Helvetica",Font.BOLD,12));
      text.glDraw(gl);
   
   } // display()


I know that glDraw works, since it successfully draws other graphics components on the screen where they should be.  there's just something wrong with the texture.  Just for quick reference, here's the code that loads and initializes the texture:

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  
// from Texture.java
public void initialize(boolean createMipMaps, boolean wrap, int minFilter, int magFilter, GL gl, GLU glu)
    {
        int[] textureID = new int[1];

        gl.glGenTextures(1, textureID, 0);
        id = 1;//textureID[0];

        gl.glBindTexture(GL.GL_TEXTURE_2D, id);

        int wrapMode = wrap ? GL.GL_REPEAT : GL.GL_CLAMP;
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, wrapMode);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, wrapMode);

        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, minFilter);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, magFilter);

        if (createMipMaps)
        {
            glu.gluBuild2DMipmaps(
                GL.GL_TEXTURE_2D,
                componentCount,
                width,
                height,
                glFormat,
                GL.GL_UNSIGNED_BYTE,
                buffer
            );
        }
        else
        {
            gl.glTexImage2D(
                GL.GL_TEXTURE_2D,
                0,
                componentCount,
                width,
                height,
                0,
                glFormat,
                GL.GL_UNSIGNED_BYTE,
                buffer
            );
        }
    }

    public void bind(GL gl)
    {
        gl.glBindTexture(GL.GL_TEXTURE_2D, id);
    }


and the IO...
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  
// from TextureIO.java
 public static Texture createTexture(BufferedImage image)
    {
        BufferedImage textureImage;
        WritableRaster raster;
        ColorModel colorModel;

        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();
        int textureWidth = getPowerOfTwo(imageWidth);
        int textureHeight = getPowerOfTwo(imageHeight);
        int textureFormat;

        if (image.getColorModel().hasAlpha())
        {
            textureFormat = GL.GL_RGBA;
            colorModel = glAlphaColorModel;
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, textureWidth, textureHeight, 4, null);
        }
        else
        {
            textureFormat = GL.GL_RGB;
            colorModel = glColorModel;
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, textureWidth, textureHeight, 3, null);
        }

        textureImage = new BufferedImage(colorModel, raster, false, new Hashtable());
        copyImage(image, textureImage);
        byte[] data = ((DataBufferByte) textureImage.getRaster().getDataBuffer()).getData();

        ByteBuffer textureDataBuffer = ByteBuffer.allocateDirect(data.length);
        textureDataBuffer.order(ByteOrder.nativeOrder());
        textureDataBuffer.put(data, 0, data.length);

        return new Texture(textureDataBuffer, textureWidth, textureHeight, textureFormat);
    }


Now all the code I've got that has anything to do with the creation of the text object has been pasted within my last few posts.  I don't see how its out of line with anything else that's been done in these threads or in any of the tutorials. 

Any thoughts? or should i just give up completely
Offline tom
« Reply #31 - Posted 2005-12-13 10:03:24 »

Another shot in the dark then Smiley

If your using the latest verision of JOGL you need to rewind the buffers. In this case textureDataBuffer need to be rewound in createTexture, before the Texture object is created. This has changed lately and it is possible the TextureLoader was writtin against an older version of JOGL.

Good luck.

Offline Antilles58

Senior Newbie





« Reply #32 - Posted 2005-12-14 00:51:40 »

 i would do that... how? Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #33 - Posted 2005-12-14 08:43:51 »

After the line "textureDataBuffer.put(data, 0, data.length);" in createTexture you add "textureDataBuffer.rewind()".

You can also add buffer.rewind() at the beginning of Texture.initalize(...) in case the buffer position is changed somwhere else in the code.

Read the javadoc for java.nio.Buffer for more information about buffers. Remember that JOGL uses position and limit of the buffers and they need to be set correctly to mark what data to use.

Offline Antilles58

Senior Newbie





« Reply #34 - Posted 2005-12-14 22:30:53 »

sweet! that got the texture to load.  however, its upside down and backwards, and the background is black.  I was able to fix the position alignment by moving my texture coords around, but why is the background black?  I'm not calling glColor3f(black) anywhere.  The parts that are black should be transparent (and are in fact transparent in the place the image appears elsewhere in my program) but aren't for some reason in this.  are there options i need to set to activate transparency?

also, i was pretty sure i had the position alignment set up right, so i think that it was upside down and backwards might have been something else that went wrong with loading the texture in.

Offline turquoise3232

Junior Member




Java (games) rock!


« Reply #35 - Posted 2005-12-14 22:39:35 »

You definitively need to enable blending...

            gl.glEnable ( GL.GL_BLEND );
            gl.glBlendFunc ( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA );
Offline Antilles58

Senior Newbie





« Reply #36 - Posted 2005-12-14 23:47:40 »

got it! Smiley thanks a LOT to everybody who helped me! I really appreciate it, even though I was annoying at times i'm sure Smiley
Pages: 1 [2]
  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.

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

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

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

Riven (15 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
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

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!