Slick Forums

Discuss the Slick 2D Library
It is currently Sat Dec 16, 2017 2:43 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Ray Creator
PostPosted: Mon Sep 10, 2012 3:37 am 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
Even though Slick is a game library, it has many other uses :D

Ray Creator is a program that lets you randomly create a ray-based image, such as the ones below, based on your options. It starts with a Swing GUI that lets you pick your options, and then when you click the button, it creates a random image using those options.

Created using Target RGB mode:
Image
Created using Greyscale mode:
Image
Created using Rainbow mode:
Image

I wish this forum supported resizing images in BBcode :(

Image window controls:
Enter: Create a new random image using the same options as the previous image.
S: Save image to a BMP file in a folder called "Saved_images" in the same spot as the EXE and Jar files.

To DOWNLOAD Ray Creator, click here, and then click the green download button. I'd give a direct link, but this way I can make sure this thread always has the most up-to-date version.

Note: Saving an image can take minutes at large resolutions on slow computers. The longest I've had it take is 30 seconds at 1280x720.

Hope you guys give it a try. Let me know what I should change/add :D

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Mon Sep 10, 2012 2:27 pm 
Offline
User avatar

Joined: Fri Dec 24, 2010 3:06 am
Posts: 90
Location: USA, Texas
Just a heads up that when I try and use the .exe for RayCreator_0-1-0-Alpha_2012-9-9, I get this error message:
Code:
This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted.
However, the .jar launches fine. Saving an image seems to be awfully slow... why does it take so long?

On the other hand, if you have the render window open and then you switch to the options menu and try to click a button, like render for instance, nothing will happen. However, once you close the rendering window the button you clicked earlier will be activated automatically.


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Mon Sep 10, 2012 7:49 pm 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
That's odd that you get an error with the exe. I downloaded the file from my link, extracted it, and successfully ran the exe without any errors. Are you on a 32-bit system? I packaged the 32-bit JRE into the exe, so that shouldn't be an issue but it could be.

Try downloading it again and see if you still get the error. Maybe your download just got corrupted somewhere along the way.

Saving an image does take a long time. Here's the code I used to save an image. Step 3 is the part that takes forever. Maybe someone can find a better way to do it.
Code:
System.out.print("Step 3: Getting image data (can take minutes)... ");
// get image data
BufferedImage bImg = new BufferedImage(myGame.screenWidth, myGame.screenHeight, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < myGame.screenWidth; x++)
{
   for (int y = 0; y < myGame.screenHeight; y++)
   {
      // gr = Slick Graphics object
      Color pixel = gr.getPixel(x, y + 1); // must be y+1. Otherwise the very bottom pixel of the screen will appear at the top of the saved image
      int a = 255;
      int r = (int)(pixel.r * 255);
      int g = (int)(pixel.g * 255);
      int b = (int)(pixel.b * 255);
      int rgb = 0;
      rgb |= (a & 255) << 24;
      rgb |= (r & 255) << 16;
      rgb |= (g & 255) << 8;
      rgb |= (b & 255);
      bImg.setRGB(x, y, rgb);
   }
}
System.out.println("Completed");

System.out.print("Step 4: Saving image data... ");
ImageIO.write(bImg, "bmp", new File(imageFolderName + File.separator + fileName));
System.out.println("Completed");

I know there's an issue in the program where when the Slick window is open, clicking anything in the Swing window won't update until the Slick window is closed. I haven't yet figured out a good way to disable the Swing window's items while the Slick window is running. I'm working on that :D

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Thu Sep 13, 2012 2:35 am 
Offline
User avatar

Joined: Fri Dec 24, 2010 3:06 am
Posts: 90
Location: USA, Texas
Alright, cool, and no, I'm running on 64-bit Windows 7 Home Premium.

It would be nice to provide, for example, an MD5 hash so people can check the file. I redownloaded the same version, but no dice, same error.


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Sat Sep 15, 2012 3:34 am 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
@dpek Thanks for letting me know about the error. I tried running the exe on my laptop and got the same error you did. Then I tried one of my older games and got the same error. That means I'm doing something wrong in NetBeans or Launch4j.

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Mon Sep 17, 2012 4:30 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
This is awesome. :) Tech demos like these are a good way to learn a library and graphics programming before diving nose-first into a monstrous game project.

Two things are contributing to your slow saves. Firstly, you are getting each individual pixel in the screen, which can be very costly since it may require hundreds of thousands of texture transfers. (Slick's getPixel wasn't really designed for this use.)

One solution would be to copy the entire screen to a Slick Image (using Graphics.copyArea) and then saving that with Slick's ImageOut utility. A better solution would be to render the effect to an offscreen image (using Image.getGraphics) instead of the screen; then simply pass the image to ImageOut.

Also, for future reference, it's more efficient to use the backing pixels of a BufferedImage instead of relying on getRGB/setRGB -- see this post.

--

I hope you don't mind: I tried re-implementing your idea using shaders (assuming you aren't already using them). Hopefully the demo shows an alternative way of achieving a starburst effect (on the GPU) as well as some standard Slick practices (like image graphics and Image IO).

Take note of how I'm using createOffscreenGraphics and saving images with ImageOut -- you will probably want to do the same for efficiency (my app saves a 2048x2048 image in a split second). I included a couple of shader effects (vignette, grayscale) which you can comment out and play around with.

Of course; a shader approach has its own limitations -- including non power of two sizes (it would take a bit of tweaking), aliasing and blurring at larger resolutions, etc. This is why your current approach (polygons?) looks better.

Image

Starbursts.java (mirror)
rect2polar.frag (mirror)
pass.vert (mirror)

You could even take your application a step further -- generate your starburst image using polygons, and then add GLSL post-processing like vignette, blurring, and other effects.


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Tue Sep 18, 2012 8:43 am 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
Wow, davedes! I'll have to take a look at your version and see what I can do to improve mine. I've built a few games using Slick before, but they never had any advanced graphics stuff (like shaders).

I looked for a way to make Slick save an image, but couldn't find anything, so I went the javax.ImageIO route. I'm glad you mentioned that Slick has utilities to save an image.

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Mon Oct 01, 2012 3:48 am 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
davedes, I tried to run your shader idea but NetBeans is telling me it can't find ShaderProgram and Image.createOffscreenImage(). It is able to find the Image class, but not that specific method. I'm using Slick build 274. Can you help me get your code working?

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Tue Oct 02, 2012 10:59 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
cmasupra wrote:
davedes, I tried to run your shader idea but NetBeans is telling me it can't find ShaderProgram and Image.createOffscreenImage(). It is able to find the Image class, but not that specific method. I'm using Slick build 274. Can you help me get your code working?

Pull the latest version of Slick or download Liam's JAR distributable from the new site.


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Tue Oct 02, 2012 11:45 pm 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
I downloaded Liam's jar since I'm using NetBeans and don't know my way around Mercurial. It says the build is 264. Is that right? 274 is older but a bigger number.

I was able to run your program now. It's too advanced for me. I have no idea how you converted vertical rainbow bars to a greyscale starburst. I know it has to do with the .frag and the .vert files, but I know nothing about shaders.

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Sun Oct 07, 2012 2:10 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
cmasupra wrote:
I downloaded Liam's jar since I'm using NetBeans and don't know my way around Mercurial. It says the build is 264. Is that right? 274 is older but a bigger number.

I was able to run your program now. It's too advanced for me. I have no idea how you converted vertical rainbow bars to a greyscale starburst. I know it has to do with the .frag and the .vert files, but I know nothing about shaders.

None of the current devs maintain or host the nightly build, so it's out of date.

It's a tad more advanced... :) But basically it just uses some math (polar vs. cartesian coordinate system) to achieve the result. It's the same as Photoshop's "Polar Coordinates" filter -- it takes the vertical bar image and applies the "shader effect" to it, transforming each toward the center. The shader also specified some other effects, such as greyscale and vignette (basic vector math), before returning the final color.


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Wed Oct 24, 2012 5:09 pm 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
I updated the program. It now saves images using Slick, so it's much faster. I think I also fixed the exe file now because it runs fine on my laptop.

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
 Post subject: Re: Ray Creator
PostPosted: Wed Oct 24, 2012 5:45 pm 
Offline
User avatar

Joined: Fri Dec 24, 2010 3:06 am
Posts: 90
Location: USA, Texas
cmasupra wrote:
I think I also fixed the exe file now because it runs fine on my laptop.
Nice job! I can confirm that the .exe works with me as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group