Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (488)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  Rendering an Image once and De-rendering on close  (Read 1205 times)
0 Members and 1 Guest are viewing this topic.
Offline Operation

Senior Newbie


Medals: 1



« Posted 2013-09-01 16:24:46 »

I'm using the Slick2d library to create a game, with a large background. I'm using
1  
2  
3  
4  
5  
6  
7  
mapback.startUse();
      for(float x = 0; x < mapwidth; x+=200){
         for(float y = 0; y < mapheight; y+=200){
         mapback.getSubImage(0,0).drawEmbedded(x,y,200,200);
         }
      }
      mapback.endUse();

to draw the same background over a large area, but it takes a bit of GPU and its slowing my game down and creating graphical glitches.

So is there a way to draw the image once (maybe in the init()) with OpenGL or something, so that i dont have to update it every loop. The image is static and only goes away when the state changes, so i will have to also dispose of the image, too.

Thanks in advance.
Online Longarmx
« Reply #1 - Posted 2013-09-01 20:20:10 »

If it's static then you could create a single image at startup out of all the tiny images. Then you could render that single image.

Offline Operation

Senior Newbie


Medals: 1



« Reply #2 - Posted 2013-09-01 20:51:07 »

That doesn't help, since the image is too big to render in one piece. That's why i cut it up and rendered the pieces in the code above, since the GPU can't handle one huge image. I've tried only rendering it under the window, but that just created a lot of flickering and graphical bugs.
My question is how to instead of rendering it every game loop, rendering it just once at the beginning of the state.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline supaFool

Junior Member


Projects: 2



« Reply #3 - Posted 2013-09-01 20:56:46 »

Assuming it is a solid color, make it smaller, then slick has a method is the Display class to scale images, Also assuming you extended BasicGameState, render it in the draw() method, this will also make it only render one time
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #4 - Posted 2013-09-01 21:02:50 »

You're saying you only want to render it once but you want it to stay there? Do you know how rendering even works?

Offline supaFool

Junior Member


Projects: 2



« Reply #5 - Posted 2013-09-01 21:06:10 »

You're saying you only want to render it once but you want it to stay there? Do you know how rendering even works?

how is this helpful to him?

I think he is saying the BG doesn't move so only has to be instantiated once. This is why no one posts here cause all they get is trolls. Help him out, or stay quite is good advice.
Offline tdegroot96

Junior Member


Projects: 1



« Reply #6 - Posted 2013-09-01 21:07:51 »

Have you tried BigImage? http://slick.ninjacave.com/javadoc-util/org/newdawn/slick/BigImage.html
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #7 - Posted 2013-09-01 21:27:44 »

You're saying you only want to render it once but you want it to stay there? Do you know how rendering even works?

how is this helpful to him?

I think he is saying the BG doesn't move so only has to be instantiated once. This is why no one posts here cause all they get is trolls. Help him out, or stay quite is good advice.
Excuse me, I'm a troll? It seems that OP doesn't know what he's asking, so I was simply asking if he knows how game programming? He doesn't need to insantiate every frame, but he sounds like he only wants to render it for one frame, and then have it dry rendered. That doesn't make any sense.

You weren't helping either.

Offline Operation

Senior Newbie


Medals: 1



« Reply #8 - Posted 2013-09-01 21:49:32 »

Thanks for all the suggestions! Firstly, my image is not a solid color, it is a black image dotted with star like shapes, so scaling will make it look weird.
I will go try out BigImage, it looks promising, but it might become obsolete when i create random background with many different star fragments later on(this is fine for now).

Sorry, i recently started creating games (i coded other applications for a while), so i don't really know how rendering works down at core levels, but if only drawing an image once and making it stay there cannot work, you could just say it.

Thanks for the suggestions.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2013-09-01 22:13:38 »

Ah yes, sorry for sounding irritated! Don't mean to!
Good luck with the game Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Operation

Senior Newbie


Medals: 1



« Reply #10 - Posted 2013-09-01 22:22:27 »

Ah, its OK.

The BigImage thing still doesn't work. I get a java.nio.BufferUnderflowException error, since apparently i'm running out of memory. I added memory by using -Xmx128m -Xms128m to give the vm more room, but still it gives the error. I've tried using other file formats such as VGA. Some more help would be appreciated, or other solutions all together.

And for rendering, i tested it that on pausing it stops rendering and everything disappeared, so i guess the solution i envisioned is pretty much impossible.
Offline StumpyStrust
« Reply #11 - Posted 2013-09-01 23:18:56 »

Quick run down on rendering.

Normally,

Update game logic.

Clear current drawing buffer. (this clears everything previously draw)

Render everything.

Swap buffers, flip, blit or w/e. Depends on how you are double buffering and what not.

repeat

Things are cleared every frame. What you seem to need is to draw the images into a texture/image and then just draw that image on the screen and not recreate said texture/image every frame. Also, what you are trying may not be the best way to go about it. If you are doing a space background (stars, planets, dust), then just rendering a bunch of star sprites may be faster due to fill rate which may be what you are hitting. If you could explain what you are trying a little more I am sure myself or some other more experienced member can help you.  Smiley

Offline Operation

Senior Newbie


Medals: 1



« Reply #12 - Posted 2013-09-02 14:23:13 »

Quick run down on rendering.

Normally,

Update game logic.

Clear current drawing buffer. (this clears everything previously draw)

Render everything.

Swap buffers, flip, blit or w/e. Depends on how you are double buffering and what not.

repeat

Things are cleared every frame. What you seem to need is to draw the images into a texture/image and then just draw that image on the screen and not recreate said texture/image every frame. Also, what you are trying may not be the best way to go about it. If you are doing a space background (stars, planets, dust), then just rendering a bunch of star sprites may be faster due to fill rate which may be what you are hitting. If you could explain what you are trying a little more I am sure myself or some other more experienced member can help you.  Smiley

Hi, thanks for the suggestions!

Ok, so i have my screen, and i'm rendering my ship, enemy ship, planets, and a bunch of other dynamic stuff. The background i am rendering is just black with some stars on it, repeated, as shown in code above. The background image is a 5000 by 2000, and im having trouble rendering it as one piece, hence the code in my first post. My question is that if could somehow make it more efficient. Your suggestion of rendering individual stars could work, only rendering the ones i could see. That has produced some problems in the past, but i'll give it a shot. I can't clarify anymore, that's basically everything on the topic.

So, maybe i could take the screenwidth and screenheight, (+camX, camY of course) and search for all sprites with coordinates in between and draw those sprites only? Would that create too much of a burden on the game, or would it be a viable option? Are there any better ways of doing this?
Offline StumpyStrust
« Reply #13 - Posted 2013-09-02 17:45:09 »

Culling out the things you do not want to draw is very very cheap for 2D games.

You have a rectangle that is what your camera can see. Anything not intersecting that rectangle is not drawn.

1  
2  
3  
4  
5  
6  
public void render()
{
     if(culled())
         return;
//render stuff
}


If you want to be lazy, you can use java's geometry classes which have all the methods to test if 2 rectangles intersect, a point is inside a rectangle, and more.

To help explain fill rate a little more lets think. 5000*2000 = 10,000,000 pixels that need to be pushed to the gpu. That does not include any other stuff you want to render. If you have say 1000 particles that use an 8*8 image, that is 64,000 pixels. Much less. I would have a static bkg that is the size of your cameras view and have this one not move. Then do the dynamic stars and maybe some space dust. That is just a personal recommendation and is by no means what you may want in visual style. But the culling code using java's rectangle class is trivial and really should be done on anything you are rending as it may not be viewable by the camera.

For 2D games, you will most likely hit a fill rate bottle neck before anything else.  Smiley

Offline namrog84

JGO Ninja


Medals: 46
Projects: 4


Keep programming!


« Reply #14 - Posted 2013-09-02 18:09:12 »

Could you share more than you are right now?  example image and more of the rendering code?

Most rendering things in 2D shouldn't be causing any slowdowns on most people's computers, unless maybe you are having millions of particles and tons of post processing shaders or something.


You should be able to render a good size images, quite a lot of them on screen. Even on very old machine with minimal issues.


I feel like everyone is trying to have a bandaid fix to something that is much deeper and seriously wrong with how something is being handled.

 Huh Pointing persecutioncomplex

"Experience is what you get when you did not get what you wanted"
Offline davedes
« Reply #15 - Posted 2013-09-02 18:48:58 »

It sounds like you're rendering a huge image. Instead, try to find way of repeating elements and making things a little more "procedural."

For example, if you're rendering a starfield, then you just need to clear the screen with black and render small star sprites somewhat randomly across the space. You can even do parallaxing, like this:
http://www.youtube.com/watch?v=u42UiIlNp0g

The above starfield probably just uses a few different 16x16 sprites.

This way you aren't rendering some massive image. Generally if you are relying on massive images for a background it's the sign of poor practice with OpenGL. Instead, aim for a max of 2048x2048 or something, and try to repeat elements where possible.

Offline Operation

Senior Newbie


Medals: 1



« Reply #16 - Posted 2013-09-02 20:20:18 »

Wow, thanks for all the suggestions everyone, i will definitely implement rendering only objects on screen. Also, i checked out the parallax scrolling video, and it looks really awesome! So i'll be figuring out a solution for that as well, and dumping the old images for individual sprite stars.
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.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (69 views)
2014-08-11 02:49:23

BurntPizza (46 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!