Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (498)
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  
  glGetTexImage alternative  (Read 2700 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2011-12-01 07:00:32 »

Hi, I'm trying to get the pixels from a 4096x1024 image. It takes 75ms.

1  
2  
3  
4  
5  
   int size = m_iWidth*m_iHeight*16;
   GL11.glBindTexture(GL11.GL_TEXTURE_2D, m_iTextureID);
   m_bbPixels = ByteBuffer.allocateDirect(size);
   GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, m_bbPixels);  
   m_bbPixels.asIntBuffer().get(m_pixels);


Is there a way I could get just part of the image instead of all of it? like a rectangle inside the image.
Or is there a faster way to do this?

Thanks,
roland





Offline theagentd
« Reply #1 - Posted 2011-12-01 10:47:00 »

Bump on this! Very interested in this too! I've heard that it should be doable with "pixel buffers", whatever that means. Google has failed me.

Myomyomyo.
Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2011-12-01 11:06:52 »

A good bit of info here on the actual use of PBOs. It does depend on what you want to do with the data afterwards as to exactly which way is best to get the data back out of a texture, or indeed why it's there in the first place (it's an unusual place to have data that you want to read back to the client).

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roland
« Reply #3 - Posted 2011-12-01 11:39:51 »

Thanks princec
Any chance at there being an LWJGL example? Cheesy I want to use it to read pixels from a rectangle inside an image.
Heres a video of the game I'm currently working on, you can see how it lags when I destroy a piece of ground because it is reading the whole image.
http://www.youtube.com/watch?v=dLyjGhSmUyA
Offline theagentd
« Reply #4 - Posted 2011-12-01 12:02:33 »

Thanks princec
Any chance at there being an LWJGL example? Cheesy I want to use it to read pixels from a rectangle inside an image.
Heres a video of the game I'm currently working on, you can see how it lags when I destroy a piece of ground because it is reading the whole image.
http://www.youtube.com/watch?v=dLyjGhSmUyA
AMAZING VIDEO, especially if you actually manage to get the ground to fall. Just, DANG.

Myomyomyo.
Offline roland
« Reply #5 - Posted 2011-12-01 12:31:42 »

Thanks!  Smiley I'll try my best!
Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2011-12-01 13:20:19 »

That looks really interesting - reminds me of Soldat (which of course is a good thing). The code in that page should be trivial to port to LWJGL as the syntax is almost identical.

Cas Smiley

Offline roland
« Reply #7 - Posted 2011-12-02 03:01:22 »

That looks really interesting - reminds me of Soldat (which of course is a good thing). The code in that page should be trivial to port to LWJGL as the syntax is almost identical.

Cas Smiley
Thanks Smiley yep, it's a Soldat clone (although with a lot of extra features). Soldat is my favourite game, I've played it for 6 years. I think it's time there is a new version!
I'll have have look and try get it working.
Thanks again,
roland
Offline theagentd
« Reply #8 - Posted 2011-12-02 10:43:07 »

I also played Soldat for a while, but this looks so much more awesome.

Myomyomyo.
Offline roland
« Reply #9 - Posted 2011-12-03 04:38:51 »

I also played Soldat for a while, but this looks so much more awesome.
Really? Thanks!  Grin

princec could you help me out here?
I reallly don't have much of an idea what I'm doing.

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  
   private void CreatePBO()
   {

      if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object)
      {
         IntBuffer buffer = BufferUtils.createIntBuffer(1);
         ARBVertexBufferObject.glGenBuffersARB(buffer);
         m_iPBOID = buffer.get(0);
      }
      else
      {
         System.out.println("Error creating PBO");
         return;
      }
     
     
      int CHANNEL_COUNT = 4;
      long DATA_SIZE = m_iWidth * m_iHeight * CHANNEL_COUNT; //width & height of texture
     
      ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, m_iPBOID);
      ARBPixelBufferObject.glBufferDataARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, DATA_SIZE, ARBPixelBufferObject.GL_STREAM_READ_ARB);

      ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, 0); //unbind
     
   }
   
   public void PBOReadPixels()
   {
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, m_iTextureID); //I need this don't I?
     
      GL11.glReadBuffer(GL11.GL_FRONT); //but i want to read from an image, not the front buffer?
     
      ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, m_iPBOID); //bind
     
      int size = m_iWidth*m_iHeight*16;

      m_bbPixels = ByteBuffer.allocateDirect(size);
      //GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, m_bbPixels);
     GL11.glReadPixels(0, 0, m_iWidth, m_iHeight, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, m_bbPixels);
      m_bbPixels.asIntBuffer().get(m_pixels);
     
     
      ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, 0); //unbind
  }


Thanks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roland
« Reply #10 - Posted 2011-12-03 04:52:03 »

Also, do I have to do ByteBuffer.allocateDirect(size); each time I read the pixels? I found that it takes 37ms to do it on my big texture. Could I just allocate once in the constructor and then use the same ByteBuffer each time?

Thanks
Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #11 - Posted 2011-12-03 05:11:07 »

@roland, You game is much more cooler looking than my scorched earth type game:
http://youtu.be/yLTETOfZLx0
I thought about making "holes" with vertexes, but couldn't figure it out on my own, so I'm just cutting away at an Image.
Keep up the good work, inspirational, and I can't wait to play your game.
Offline roland
« Reply #12 - Posted 2011-12-03 05:42:21 »

@roland, You game is much more cooler looking than my scorched earth type game:
http://youtu.be/yLTETOfZLx0
I thought about making "holes" with vertexes, but couldn't figure it out on my own, so I'm just cutting away at an Image.
Keep up the good work, inspirational, and I can't wait to play your game.
Thanks  Smiley
Your game is looking good. Do you randomly generate the ground? or do you load images from a file?
I once tried to make a game like yours, and it kind of worked, I think it would have been fun if I had stuck with it.
I'll try to put a link up, although its extremely buggy and incomplete, just to show you an idea.

Some tips: In my game I have a scrolling background picture, you could put a different one in than the gradient image, or have multiple background images with the further back ones moving slower than the ones in front. You should also put some scenery images in such as trees and buildings.

You could also when exploding the ground, making particles fly up that the same colour of the pixel you destroyed, and also make pixels "fall down" if there are no pixels below them. (check

1  
if ((image.getPixel(x,y) != 0) && (image.getPixel(x,y+1) == 0)) image.setPixel(x,y+1,image.getPixel(x,y)); 


Although I dont recommend using get and setpixel cos it's real slow. But you get the idea?

You could also maybe use the mouse to control aiming since they are humans although that would be annoying for multiplayer on one PC.

It would be cool if you made it multiplayer, turn based but everyone shoots at the same time (or they have 10 seconds to shoot or something))
But that's just my ideas.

True, tracing an image is quite hard (especially to make it fast), so I hope I can make it work. The good thing about using vertices is the physics are much easier than pixel physics (atleast for my game). So there wasn't an easy choice.

Hope that helped,
roland




EDIT: here's the game: www.chaosreef.com/underfire/underfire.php
the timing is completely STUFFED, but look at what happens when the terrain is destroyed  Smiley

go single player -> level 1 start -> wait for it to load

click on top left to choose towers and choose stone cannon
click somewhere above the ground and create a few towers.
Then click (B) on the top right (battle phase)
use mouse to aim and hold down left click for power.

The game will probably crash after a few shots xD







Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #13 - Posted 2011-12-03 06:14:37 »

Ground is randomly generated, yes, then I texture it and drop Grass on it.  I am planning on having Parallax scrolling in the future (showing the other side of the map).  I did have mouse aim, but as you might have been able to tell from the video, the map is an endless loop so determining if the angle should be to the left or right was a pain.  During testing I found my self shooting a bullet (not affected by gravity) when my player was off screen, and saw the bullet come from the opposite side of the screen than I expected.  It is (when it's done) turn based, each player has 30 sec to move and shoot and 3 secs after shooting to move (hide).  Not every player goes in the same order, it depends on the cool down time of the weapon you used last as to when you get to go next.  I'm not going to have falling ground.  I like the idea of building a cave, with a rocket launcher, to hide in (like I used to do in Worms).
Offline roland
« Reply #14 - Posted 2011-12-04 02:00:39 »

sounds fun  Smiley hope it goes well.

BUMP on post #9 & 10
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 (27 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (193 views)
2014-04-01 02:16:10
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

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