Texture different in mac and linux

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Texture different in mac and linux

Lili
Hello. I'm struggling with my textures and I would really appreciate some help.
I have a piece of code which renders a texture from a jpg file. The code gives different result for Linux and Mac and I can't understand if I am the cause for the problem (probably yes). On both machines I'm using Java 7 and the latest jogl libraries (since December 2013).
The code is giving me the results that I want on the Linux Machine. On the Mac, however, if the animator is running the image shows for a second and then it shrinks to an invisible size. If I don't start the animator the image stays but is smaller that the square that I'm trying to map it onto. I am inerting screenshots of what the results look like.Result on LinuxResult on mac with the animator offResult on mac with the animator running
I am also attaching my code (and the 2 shaders). I think it's simple enough. The java class is  justTexture.java, the vertex shader colorTexture.vert and the fragment shader colorTexture.frag.
I suspect that maybe I'm doing something wrong when I activate and bind the texture or when I send the sampler2D location to the shader.
This is where I initializa the texture
texture = TextureIO.newTexture(new File("Varna.jpg"), false);
                byte[] buf = new byte[texture.getWidth()*texture.getHeight()*4];
                ByteBuffer buffer = ByteBuffer.wrap(buf);
                gl.glGenTextures(1, textureId, 0);  
                gl.glActiveTexture(GL3.GL_TEXTURE0);
                gl.glBindTexture(GL3.GL_TEXTURE_2D, textureId[0]);  

                gl.glTexImage2D(GL3.GL_TEXTURE_2D, 0, GL3.GL_RGBA, texture.getWidth(), texture.getHeight(), 0, GL3.GL_RGBA, GL3.GL_UNSIGNED_BYTE, buffer);
                texture.setTexParameteri(gl, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_LINEAR);
                texture.setTexParameteri(gl, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_LINEAR);

then I create a location for the sampler
         iSampler = gl.glGetUniformLocation(iTexProgram, "Tex1");

and the code below goes in the display function
        gl.glUseProgram(iTexProgram);
        gl.glUniformMatrix4fv(iTexMVP, 1, false, texMVP, 0);
        gl.glUniform1i(iSampler, 0);
        gl.glBindVertexArray(iVao[0]);
        gl.glDrawArrays(GL3.GL_TRIANGLES, 0, 6);
        gl.glBindVertexArray(0);

Thank you in advance for your help. I really appreciate it.
Reply | Threaded
Open this post in threaded view
|

Re: Texture different in mac and linux

gouessej
Administrator
Hi

This has nothing to do with the operating system. One of your graphics cards (under Mac) doesn't support non power of two textures.

Edit.: Please use at least JOGL 2.1.4 before investigating further.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Texture different in mac and linux

Lili
Thank you for the response gouessej. I updated my jogl (I didn't realize there was an even newer release than December) and I made my picture 256x256. That gave me the same results.
However, I switched back to Java 6 and now it's working just the way I want it to :)
Reply | Threaded
Open this post in threaded view
|

Re: Texture different in mac and linux

gouessej
Administrator
I don't understand why switching to Java 1.6 solved your problem :s

Edit.: Use NEWT instead of Swing and AWT. Maybe there is a bug in Oracle Java 1.7 that affects heavyweight / lightweight mixing.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Texture different in mac and linux

Lili
I am confused too.
Thanks for the suggestion to use NEWT. I will try it next week and will post again with the results.
Reply | Threaded
Open this post in threaded view
|

Re: Texture different in mac and linux

Xerxes Rånby
In reply to this post by Lili
Hi i uploaded your example to
https://github.com/xranby/jogamp-forum-examples/tree/master/Lili/justTexture

git clone https://github.com/xranby/jogamp-forum-examples
cd jogamp-forum-examples/Lili/justTexture
./fetch-jogamp-build.sh
./run.sh

Since i did not have access to your Varna.jpg image i added one i found on the internet that was free for use on desktop systems.
It work on my linux system.
Reply | Threaded
Open this post in threaded view
|

Re: Texture different in mac and linux

Xerxes Rånby
In reply to this post by Lili
Lili wrote
I am confused too.
Thanks for the suggestion to use NEWT. I will try it next week and will post again with the results.
I added an AWT -> NEWT port of your example that you can try
https://github.com/xranby/jogamp-forum-examples/commit/04e1064fecd54df1b7c16b45d9c3fcd920e536dc
Reply | Threaded
Open this post in threaded view
|

Re: Texture different in mac and linux

Lili
gouessej and Xerxes Rånby, thank you both so much for you help. NEWT seems to have solved all my problems on both Linux and Mac using Java 1.7