Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
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  
  Creating a JOGL Texture object from the contents of a FBO.  (Read 2884 times)
0 Members and 1 Guest are viewing this topic.
Offline Rejechted

Senior Devvie

Medals: 2
Projects: 2

Just a guy making some indie games :D

« Posted 2011-11-17 17:22:57 »


We are using a FBO to draw our minimap and would like to obtain a JOGL texture object from it.  Currently the only way I know of for creating JOGL textures is this line in our texture loader:

TextureIO.newTexture(url, false, "png");

Where url is a URL object to the resource.

If we have a JOGL FBO, what steps can we take to obtain a com.jogamp.opengl.util.texture.Texture?

EDIT: A quick Google turned up this.  Any caveats to using this method?
TextureIO.newTexture(int target)
//Creates an OpenGL texture object associated with the given OpenGL texture target.

Silver Goblet Games' first released product:
Offline lhkbob

JGO Knight

Medals: 32

« Reply #1 - Posted 2011-11-17 17:39:33 »

I think that might only create the texture id for the texture, but will not allocate any image data for (i.e. with a call to glTexImage2D()).  You need to have image data before you can attach the texture to an FBO to specify the width, height, and format of the texture.

Offline Rejechted

Senior Devvie

Medals: 2
Projects: 2

Just a guy making some indie games :D

« Reply #2 - Posted 2011-11-18 17:14:01 »

Yeah, the above didn't work.  Is there some way to obtain a TextureData by using glReadPixels?

Silver Goblet Games' first released product:
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight

Medals: 32

« Reply #3 - Posted 2011-11-18 17:32:52 »

What exactly didn't work?  It should work if you allocated image data of the correct dimensions and attached it to the FBO properly.

Alternatively, if you've already created the FBO (with attached textures) you can wrap the OpenGL texture id with a Texture instance by calling:
newTexture(int textureID, int target, int texWidth, int texHeight, int imgWidth, int imgHeight, boolean mustFlipVertically);
//Wraps an OpenGL texture ID from an external library and allows some of the base methods from the Texture class, such as binding and querying of texture coordinates, to be used with it.

There might be a problem with your FBO setup, could you post that code?

Offline theagentd

« JGO Bitwise Duke »

Medals: 946
Projects: 4
Exp: 8 years

« Reply #4 - Posted 2011-11-18 17:45:31 »

The following code is for LWJGL, but the OpenGL commands should be exactly the same except for the GL11 part.
//Let OpenGL give us an ID.
IntBuffer id = BufferUtils.createIntBuffer(1);
int textureID = id.get();

//Setup parameters
GL11.glTexParameteri(id, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
GL11.glTexParameteri(id, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
... //Clamping, e.t.c.

//Be sure to glClear your FBO before using it (like you normally would when rendering to anything)!!!
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null);

//You now have an allocated texture accessable using textureID. Wrap it in the method Ihkbob submitted or something.
return whereverThisMethodIs.newTexture(textureID, width, height, width, height, true); //Flip might be a good idea

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

numerical (71 views)
2017-02-21 07:32:16

numerical (72 views)
2017-02-21 07:31:46

theagentd (176 views)
2017-02-18 13:42:33

theagentd (179 views)
2017-02-18 13:35:16

h.pernpeintner (1342 views)
2017-01-24 22:39:11

h.pernpeintner (1330 views)
2017-01-24 22:38:32

Galdo (1891 views)
2017-01-12 13:44:09

Archive (1978 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2517 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2310 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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‑
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!