Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  [Solved] Loading custom mipmaps fails  (Read 2848 times)
0 Members and 1 Guest are viewing this topic.
Offline Andi

Senior Newbie





« Posted 2008-04-16 20:07:15 »

Hi,

I want to load my manually created mimaps for a texture, not those generated by OpenGL.
My code:

1  
2  
3  
4  
5  
6  
7  
Texture texture = TextureIO.newTexture(myInputStream, false, "png");
for (int i = 1; true; i++)
{
   TextureData mipmap = TextureIO.newTextureData(myMipMapStream[i], false, "png");
   texture.updateSubImage(mipmap, i, 0, 0);
   if (mipmap.getWidth() <= 1) break;
}


There is no error, but the texture is only displayed black ( - at least without alpha, as it should have).

The input streams are ok, loading each texture works.

Also automatic generating works:

1  
Texture texture = TextureIO.newTexture(myInputStream, true, "png");


Any idea?
Thanks Smiley

Slam Soccer 2006 - The free football game
Offline Andi

Senior Newbie





« Reply #1 - Posted 2008-04-29 12:24:32 »

*push*
Any idea?

Slam Soccer 2006 - The free football game
Offline Spasi
« Reply #2 - Posted 2008-04-29 15:58:53 »

1  
texture.updateSubImage(mipmap, i, 0, 0);

If this is calling TexSubImage2D, try replacing it with TexImage2D.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Andi

Senior Newbie





« Reply #3 - Posted 2008-11-21 22:42:10 »

If this is calling TexSubImage2D, try replacing it with TexImage2D.

Thanks!! This was the solution.

I think this is a bug in JOGL.

Detailed explanation:

I want to create a texture with manually loaded mipmaps. So I create a texture with auto-mipmap off. Now I want to add the mipmaps. This fails, because glTexSubImage2D is only allowed, if the corresponding image already exists. But it doesn't, because I disabled auto-mipmap and so there is only level 0 available!

OK, you could say, that I may not call updateSubImage when there are no mipmap images. But I have no choice: There is neither a method to set mipmap images (updateImage has no parameter for the mipmap level), nor can I first enable auto-mipmap and then overwrite the mipmaps (JOGL doesn't allow to change the mipmap images in this case).

Suggestion: Add a parameter for the mipmap level to Texture.updateImage and the problem is solved.

Can you fix that, please?

Slam Soccer 2006 - The free football game
Offline Chris61182

Junior Member





« Reply #4 - Posted 2008-11-23 08:37:01 »

I think this is a bug in JOGL.

In short no, http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texsubimage2d.html

I refer you to the 2nd error condition...

Quote
GL_INVALID_OPERATION is generated if the texture array has
     not been defined by a   previous glTexImage2D operation.

I could go into the uglinesses of OpenGL's textures and mipmap pyramids and the bizarre things you can legally do with them that no sane person would ever have reason to do in a real app. But the short and sweet of it is a glTexImage call defines the allocation's size for each mip level, otherwise glTexSubImage is attempting to operate on undefined data over an undefined range.
Offline Andi

Senior Newbie





« Reply #5 - Posted 2008-11-23 16:01:50 »


This is exactly what I meant when I said:

Quote
OK, you could say, that I may not call updateSubImage when there are no mipmap images. But I have no choice: There is neither a method to set mipmap images (updateImage has no parameter for the mipmap level), nor can I first enable auto-mipmap and then overwrite the mipmaps (JOGL doesn't allow to change the mipmap images in this case).

The "bug" is, that JOGL does not allow me to define custom mipmaps (if so, please tell me, how), although this would be trivial to do by adding a mipmap level parameter to the setTexImage2D method.

Slam Soccer 2006 - The free football game
Offline Chris61182

Junior Member





« Reply #6 - Posted 2008-11-23 18:07:10 »

I think I see what you mean, there's no level argument to Texture.updateImage(), sorry about that. I've not looked at that code but I would imaging that call in particular is probably a fairly simple wrapper around glTexImage. The fastest way to get the changes into the project would be to make them yourself and submit them. Hopefully Ken Russell can chime in a bit here on how to do that.
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #7 - Posted 2008-11-24 03:50:02 »

The way to do this with the current code would be to first load your mipmaps into an array of TextureData objects, and then allocate one TextureData with an array of Buffers, where the Buffers come from the original TextureDatas. Then create the Texture from the TextureData containing the mipmaps.

Does that solution work for you?

Agreed that there is functionality missing from the current code, but the JOGL 1.1.x branch is not being actively maintained right now, and the JOGL 2 branch (JOGL_2_SANDBOX branch in the source tree) is not ready for broad consumption yet. If you would like to submit a patch against the JOGL_2_SANDBOX branch that would be very welcome.
Offline emzic

Senior Member





« Reply #8 - Posted 2008-11-24 13:05:47 »

Agreed that there is functionality missing from the current code, but the JOGL 1.1.x branch is not being actively maintained right now, and the JOGL 2 branch (JOGL_2_SANDBOX branch in the source tree) is not ready for broad consumption yet. If you would like to submit a patch against the JOGL_2_SANDBOX branch that would be very welcome.

JOGL_2 ? this sounds interesting! :-)
i quickly looked into the CVS but could not find any branch like this. is it publicly available yet?

what is new in JOGL 2?

thanks!

www.embege.com - personal website
webstart blendinspect - OpenGL BlendingModes visualization.
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #9 - Posted 2008-11-26 01:01:39 »

The branch name is JOGL_2_SANDBOX. The branch exists on the gluegen, jogl and jogl-demos workspaces. cvs co -r JOGL_2_SANDBOX gluegen jogl jogl-demos

The major features of JOGL 2 are elimination of AWT dependencies from the core JOGL API (although the GLCanvas and GLJPanel still exist in a sub-package) and support for multiple OpenGL profiles, like GL2 for the desktop, GLES1 for OpenGL ES 1.x and GLES2 for OpenGL ES 2.0, as well as common subsets. With the common subsets you can develop on the desktop and deploy onto mobile devices.

The work is still in early stages and some stuff is broken. We'll post more once it's in better shape for public consumption and broader feedback.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Andi

Senior Newbie





« Reply #10 - Posted 2008-12-04 19:23:50 »

The way to do this with the current code would be to first load your mipmaps into an array of TextureData objects, and then allocate one TextureData with an array of Buffers, where the Buffers come from the original TextureDatas. Then create the Texture from the TextureData containing the mipmaps.

Thanks for this idea, works perfectly! I will submit a patch for JOGL2 as soon as it is available and I use it.

Here is the working code now:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
//load all mipmaps levels
LinkedList<TextureData> mipmapLevels = new LinkedList<TextureData>();
for (int i = 0; true; i++)
{
   TextureData mipmapLevel = TextureIO.newTextureData(openDataFile(i), false, "png");
   mipmapLevels.add(mipmapLevel);
   if (mipmapLevel.getWidth() <= 1)
      break;
}
//collect buffers
Buffer[] buffers = new Buffer[mipmapLevels.size()];
int level = 0;
for (TextureData mipmapLevel : mipmapLevels)
{
   buffers[level] = mipmapLevel.getBuffer();
   level++;
}
//create the texture
TextureData top = mipmapLevels.getFirst();
TextureData textureData = new TextureData(top.getInternalFormat(), top.getWidth(), top.getHeight(),
   0, top.getPixelFormat(), top.getPixelType(), false, false, buffers, null);
Texture texture = TextureIO.newTexture(textureData);

Slam Soccer 2006 - The free football game
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.

xsi3rr4x (55 views)
2014-04-15 18:08:23

BurntPizza (53 views)
2014-04-15 03:46:01

UprightPath (66 views)
2014-04-14 17:39:50

UprightPath (49 views)
2014-04-14 17:35:47

Porlus (66 views)
2014-04-14 15:48:38

tom_mai78101 (90 views)
2014-04-10 04:04:31

BurntPizza (151 views)
2014-04-08 23:06:04

tom_mai78101 (246 views)
2014-04-05 13:34:39

trollwarrior1 (204 views)
2014-04-04 12:06:45

CJLetsGame (211 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!