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 (499)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 10
1  Java Game APIs & Engines / OpenGL Development / Re: LWJGL Antialiased lines on: 2013-10-05 13:38:34
Thanks for the replies everyone!

I made a Soldat CTF map once, called Crusade. Smiley
Smiley

LWJGL's Display.create() has an overloaded version that takes a PixelFormat. One of the PixelFormat's constructors allows you to turn on anti-aliasing and set how many samples you want.

Here is an example using 4 samples:
1  
2  
// parameters: 0 alpha bits, 8 depth bits, 0 stencil bits, 4 samples
Display.create(new PixelFormat(0, 8, 0, 4));

Is there a way I can check support for this? GLContext etc. Doesn't seem to work until the display is actually created.

@Mac70
Blending doesn't help with geometry like lines.

@roland

when you only want to activate multisampling aka. anti-aliasing for some geometrie like your minimap, you can do it like this.

1. create a multisamples RenderBuffer
2. render to that buffer
3. copy/blit the result to the screen or texture which you want to render

Code should look like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
// creating a multisampled renderbuffer
int samples = 4;//you can query the max supported samples by glGetIntegerv(GL_MAX_SAMPLES, out, 0);

int[] id = new int[1];
glGenRenderbuffers(1, i, 0);
glBindRenderbuffer(GL2ES2.GL_RENDERBUFFER, id[0]);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, width, height);

//blitting the buffer to the screen or a texture
//bind the renderbuffer as colorbuffer to a FBO
 glBindFramebuffer(GL_READ_FRAMEBUFFER, id);//bind this FBO as read buffer
 //now bind the default Framebuffer(0: the screen) or a FBO with the texture
 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, id2);

  //and as a last step copy the content of the multisampled renderbuffer
 glBlitFramebuffer(0, 0, width, height, 0, 0, dstWidth, dstHeight,  GL_COLOR_BUFFER_BIT, GL_LINEAR);


In your case I would do the rendering like this.
Clear the multisampled renderbuffer to some semi transparent black(like in your screenshot)
Render the minimap into it
Copy the renderbuffer into a texture(this step is needed to resolve the multisampling)
render the texture into the top right corner of your screen.

The thing is if you wouldn't need a transparent minimap background, you could directly copy the minimap onto the screen.


ps:
Some googling unearthed this nice trick: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter22.html
Will creating a multisampled renderbuffer simply achieve the same effect as using full screen antialiasing overriding the default Display.create()? (apart from being faster due to only being applied to the minimap) If so, unfortunately the results aren't too great. I will need to go for a more complicated technique.

Anti-aliased lines is actually pretty challenging in OpenGL.

You could use GL_LINES and line smoothing. Unfortunately, it won't look the same across all platforms. Some will use anti-aliasing, and others will not.

If you want truly consistent smooth lines in OpenGL, you have some options:

1. Use software rendering to draw the lines to a texture. If you are only targeting desktop, you can make use of Java2D to do the rasterization for you. Basically the step is just to render your Graphics to a BufferedImage, and then copy the pixels to a ByteBuffer and upload them to a GL texture.

https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-&-Java2D

This is really slow, and not something you should be doing every frame.


2. Use multi-sampling like Danny02 said.

3. Use triangles and calculate the anti-aliasing in a shader. This sounds a little daunting, but it just requires a little bit of vector math and a decent grasp of shaders. It also produces really high-quality lines, and gives way to other effects like stippling patterns, outer glows, and smooth color interpolation.

You can also achieve this without a shader, just by using a lookup texture to create a blurry line edge. The problem with this is that the anti-aliasing isn't as accurate and doesn't scale.

Both approaches are discussed here:
http://www.java-gaming.org/topics/circular-health-bar/29791/msg/274139/view.html#msg274139

(There is code at the end of the Swiper tutorial that should give you smooth lines.)

For each point in your line, you simply 'extrude' it along the perpendicular depending on the line thickness. Using triangle strips, you only need 2 vertices for every point in your line. A more complex approach would be to use a miter join, with one technique described here:
https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader#23286000001269127

More advanced still would be to support different types of joins.
http://artgrammer.blogspot.ca/search/label/opengl

4. Another solution which might work for you case is to apply FXAA or another AA technique done in the fragment shader. Since you are rendering your mini-map to a small texture, the impact shouldn't be too significant.
Thanks, I'll have a look  Smiley

2  Java Game APIs & Engines / OpenGL Development / LWJGL Antialiased lines on: 2013-10-04 15:18:53
Hi, I am making a minimap for my game. (See top right corner of below image)



Everything is perfect, except for the jagged outline. I draw lines around the edges of the map, but they aren't smooth.

I've played around with the following settings:
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

and they just make the lines look worse. Searching on google, I came across something called multisampling, I'm not sure if this is what I want though.

Note, this is rendering to a seperate texture. I don't want full-scene antialiasing, just for the lines that make up the background of the minimap.

Can anyone help me?
Thanks,
Roland
3  Games Center / Showcase / Storm2D on: 2013-05-12 07:47:28
After 2 years of development I am able to release an alpha version of Storm2D.  Smiley
Storm2D is a multiplayer 2D side-scroller inspired by Soldat and Liero.



Video

Current features:
-Multiplayer online using Quake III network model
-Unique destructible polygon terrain
-Completely Verlet physics based (Ragdolls, players, pickups, etc)
-Ability to load Soldat maps
-Custom profiles
-Hugely customisable weapons, physics, etc
-Scripted character classes, bonuses, AI, ...
-Capture the flag and Deathmatch game modes

Future features:
-Vehicles, buildings
-multiplayer map editor
-campaign and missions
-Many more battle game modes
-Mod support

Right now there are many bugs that need to be removed. This will be the focus for the next few weeks.
If people could test the game and tell me whether or not it works on their operating system, that would be great.

Linux 32/64 bit and Mac versions are UNTESTED. The linux 64 bit server runs fine (Is currently running on my 64 bit ubuntu VPS) but I haven't been able to test the clients as only have access to a windows PC at this time.

Download the game here.


NOTE: All content taken from Soldat is temporary and used with the expressed permission of Michal Marcinkowski, the creator of Soldat. If you have any issues, please email him at michal.marcinkowski<at>gmail.com.
4  Game Development / Newbie & Debugging Questions / Re: How to encrypt our code. on: 2013-03-24 08:22:09
Try obfuscation + wrapping it in an EXE or converting it to EXE through tools like Excelsior JET.

You can't "encrypt" bytecode. There has to be something that will decrypt it to run it and that could be also broken. The reason you would want to protect bytecode is because it's easily reverse-engineered. Obfuscation allows for harder reverse-engineering and converting to native makes it even harder.

I do think it's useless though, code is cheap. Art is much more valuable and what people will want and *that* is what you should protect.

Code Isn't cheap Smiley Imagine coding a game for 2 years, releasing it without it being obfuscated. Instantly anyone can decompile the class files into THE EXACT code you made (search jd-gui on google). They now know exactly how your code works, they can modify your game and produce their own version of it, in order to very easily hack/crack the game and distribute it over the internet.

If code was cheap you wouldn't get programming jobs paying you over $60 an hour Wink

I have been working on my game for over a year and a half. I don't even want to guess how many hours of frustration and hard work I put into it, I wouldn't want some random to have access to the code just like that. But that's just me. If you are making an open source game then its fine.

Everyone who values the code they have written and don't want the general public to be able to read it should use proguard. Trying to find out what a large obfuscated program does IMO will be harder than coding it from scratch.
jd-gui is also a useful tool to test if your program has been obfuscated correctly.
5  Game Development / Newbie & Debugging Questions / Re: Java reading file problem only occurs on some PC's on: 2013-03-14 00:30:05
Just from reading the title I got the idea that it might be the PC's partition format.
Ah yeah, sorry the topic title wasn't very clear  XD
But the problem is solved now Smiley
Thanks
6  Game Development / Newbie & Debugging Questions / Re: Java reading file problem only occurs on some PC's on: 2013-03-13 15:21:13
You might also look at Cortex Command. It seems to have some of the same things in it. But I've never played Soldat and am just basing things on the video of the game you posted. >.> I have played KAG though, and they're somewhat similar.
Yeah Cortex command is a great game too Smiley
I played that a lot for a while. I haven't played online with it though, just with some friends on a single PC.
7  Game Development / Newbie & Debugging Questions / Re: Java reading file problem only occurs on some PC's on: 2013-03-13 15:13:35
I think King Arthur's Gold has taken over.

Cas Smiley

KAG is a good game, but completely different to Soldat IMO. Nothing beats a good game of Soldat  Grin
8  Game Development / Newbie & Debugging Questions / Re: Java reading file problem only occurs on some PC's on: 2013-03-13 12:03:29
Game looks ace btw. Soldat's one of my favourite games of all time.

Cas Smiley

Thanks man!  Smiley
Same. I wish I could go back to the old Soldat days! I played that game almost every day for nearly 5 years. This is one of the reasons why I am making a Soldat clone. People have left the game but nothing has replaced it.

There's still a heap of bugs and things I need to do and features to add, but if I can get some good artwork, etc I think this game could be a hit. Just need to keep at it!
9  Game Development / Newbie & Debugging Questions / Re: Java reading file problem only occurs on some PC's on: 2013-03-13 11:58:39
Try to specify the locale of the scanner to match the number format of the read files.

Omg! thanks!  Smiley
That was the problem.
I didn't even know about locales Smiley you learn something new every day.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Scanner scan = new Scanner("0.0");
     
System.out.println("Locale: US");
scan.useLocale(Locale.US);
System.out.println("Has next float: " + scan.hasNextFloat());
System.out.println("Has next double: " + scan.hasNextDouble());

System.out.println("Locale: France");
scan.useLocale(Locale.FRANCE); //also GERMAN, ITALIAN, etc.
System.out.println("Has next float: " + scan.hasNextFloat());
System.out.println("Has next double: " + scan.hasNextDouble());


Output:
1  
2  
3  
4  
5  
6  
Locale: US
Has next float: true
Has next double: true
Locale: France
Has next float: false
Has next double: false



Now I just need to remember to never create a Scanner without setting the locale(I made a utility function, but creating Scanners is such a habit  Grin)
10  Game Development / Newbie & Debugging Questions / Java reading file problem only occurs on some PC's on: 2013-03-13 06:03:36
Hey,
For the last year and a half or so I've been working on a Soldat clone, called Storm2D. (http://storm2d.net)
Having released an alpha version of the game, on my latest video (http://www.youtube.com/watch?v=0Eb-4QJHHeQ) two people have posted that the game crashes at a specific point, both using Windows 7 (same as me). Annoyingly, the problem doesn't happen on my computer, nor 3+ other computers I tested the program on, so it is hard to debug. One of the users helpfully posted the crash log (exception stack trace) and it leads me to believe (although I could be wrong, as the location of the crash is not where the actual problem is) that my problem has something to do with the way I am reading files with the Java scanner.

Note: I bundle the jre with my application so it isn't a problem with different versions of java.

when reading through one of my (biped) files needed for the game, at the start of the line I check if the first 'token' in the line is a number. If it is a number, it means I need to read an extra two parameters at the start. I read the line a slightly different way (because the line contains different parameters). For some reason I think the first token is not being recognized as a number on their machines which means that the first two tokens aren't handled and the whole line is read wrongly.

The code I use to check if the token is a number(note: any type of number, float,double, int etc) is below. Does this handle all cases? (apart from long, huge numbers won't occur)

1  
2  
3  
4  
5  
6  
if (scan.hasNextFloat() || scan.hasNextInt())
{
    ... //process the first two tokens
}

//continue to read the rest of the line.


Alternatively I could use the below code and just use scanner.next() rather than using the other methods(hasNextFloat, etc), but I won't know if it works until one of the users that had the problem in the first place try it again.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public static boolean isNumeric(String str)  
{  
  try  
  {  
    double d = Double.parseDouble(str);  
  }  
  catch(NumberFormatException nfe)  
  {  
    return false;  
  }  
  return true;  
}


Thanks,
Roland


11  Game Development / Newbie & Debugging Questions / Re: Alt-f4 close with multiple threads on: 2013-02-11 12:21:52
Thanks  Smiley
12  Game Development / Newbie & Debugging Questions / Alt-f4 close with multiple threads on: 2013-02-11 11:00:54
Hi, just confirming, does alt f4 completely destroy the process (and all threads)? or is there some cases where if a thread that is not the main thread is stuck in an infinite loop, the program won't close properly?

Thanks,
roland
13  Java Game APIs & Engines / Java Sound & OpenAL / Re: Slick util OpenAL get song length on: 2012-12-09 11:07:32
Thanks davedes Smiley
A combination of a + b sounds good for me, streaming at normal speed and saving the length to a file when the song finishes.
14  Java Game APIs & Engines / Java Sound & OpenAL / Slick util OpenAL get song length on: 2012-12-09 05:52:38
Hi, I am trying to get the length of a song with OpenAL.
The song streamed rather than fully loaded. I am using .ogg files. A java version of the below code just returns 0.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
ALfloat GetBufferLength(ALuint buffer)
{
    ALint size, bits, channels, freq;

    alGetBufferi(buffer, AL_SIZE, &size);
    alGetBufferi(buffer, AL_BITS, &bits);
    alGetBufferi(buffer, AL_CHANNELS, &channels);
    alGetBufferi(buffer, AL_FREQUENCY, &freq);
    if(alGetError() != AL_NO_ERROR)
        return -1.0f;

    return (ALfloat)((ALuint)size/channels/(bits/8)) / (ALfloat)freq;
}


I think it's because the song is streaming? Is there any way to fix this?
thanks,
roland
15  Java Game APIs & Engines / Tools Discussion / Re: Proguard include library warnings on: 2012-11-13 10:43:05
Thanks Smiley
I accidentally also added my library jars as program inputs (rather than library inputs). oops xD

roland
16  Java Game APIs & Engines / Tools Discussion / Proguard include library warnings on: 2012-11-11 07:37:10
Hey, I have a problem.
I am trying to use proguard and I include quite a few libraries:
rhino javascript, jbox2d, poly2tri, slf4j, lwjgl, etc.

When i try to obfuscate my jar, I have to add these dependencies.
The problem is, they all have dependencies, which have dependencies, .....
It looks like I have to end up adding over 100 different libraries in, even though they aren't actually needed to run the unobfuscated jar file.

Is there an easier / better way to do this?
thanks,
roland
17  Game Development / Newbie & Debugging Questions / Re: Bundling JRE Windows/Linux/Mac on: 2012-10-24 14:17:13
While we are waiting for someone to give us an answer  Wink

I've only ever done Windows myself but I need to switch to embedded VMs for both Mac and Linux as well. All ears here Smiley

Cas Smiley
So at the moment if you are on linux or mac you need to install java yourself before playing the game? do you have any estimate how much this decreased the likelyness of the average user wanting to try out one of your games?

Also, if not bundling the JRE they need to add java as an environment variable Sad
18  Java Game APIs & Engines / OpenGL Development / Re: Hiding mouse cursor on: 2012-10-24 09:53:04
Thanks davedes! it works perfectly Smiley
19  Game Development / Newbie & Debugging Questions / Bundling JRE Windows/Linux/Mac on: 2012-10-24 08:08:20
Hello,
What is the best way to bundle a JRE with my application? I only have a windows computer at home so it is hard for me to test this. I have no idea even how to get the linux and mac JREs and then extract them onto my computer, so that I can put the jre folder inside my game directory.

Can someone help me out?
Thanks,
roland
20  Java Game APIs & Engines / OpenGL Development / Hiding mouse cursor on: 2012-10-24 03:36:34
Hey, I have a problem.
I might use
1  
Mouse.setGrabbed(true);
which is fine, but in the case where I want to be able to use the mouse outside the window:


1  
2  
Cursor emptyCursor = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null);
Mouse.setNativeCursor(emptyCursor);

taken from http://lwjgl.org/forum/index.php?topic=594.0

This doesn't actually completely hide the cursor. It creates a 1x1 BLACK pixel cursor.
I have tried to create an int buffer that contains a single integer with no alpha (eg new Color(0,0,0,0).getRGB()), this doesn't work.

Anyone have any ideas?

21  Game Development / Networking & Multiplayer / Re: Questions about TCP sending and packet size on: 2012-09-05 08:58:57
I wrapped a class to read and write primitives over network, if you're intersted, it works like this:

1  
2  
3  
4  
5  
6  
//Client sending message
PomPackage p = new PomPackage();
p.insert(35);
p.insert('c');
p.insert(new byte[30]);
sendPackage(p);


1  
2  
3  
4  
//Server reading the message:
int x = (Integer)p.pollQueue();
char c = (Character)p.pollQueue();
byte data[] = (byte[])p.pollQueue();


I might have reinvented the wheel but it works pretty nice, tell me if you're intersted.

I actually made something very like this for my UDP library Smiley
Thanks for the offer though!
22  Game Development / Networking & Multiplayer / Re: Questions about TCP sending and packet size on: 2012-09-05 08:52:20

I read up that the maximum packet size for ethernet is 1500 bytes, do I have to worry about this, or does TCP take care of it? eg. Should I write 1024 bytes at a time and flush after each?

Roland

TCP takes care of it. Just make sure you read all the bytes you're expecting before stopping reading.

I recommend the approach I said in my last message: read an int (the size) then readFully(size). The first int will always be consistent, as well as the readFully (as long as your size is correct!), and with that you only need to flush once in the sender after the data is sent.

Thanks Smiley that works perfectly, woot no more corrupted packets  Grin
I can't actually use a short / char because my packets will be larger than 65536 bytes, but this is only from server to client. If the client is sending I'll use this precaution.
23  Game Development / Networking & Multiplayer / Re: Questions about TCP sending and packet size on: 2012-09-05 02:39:36
Thanks for the replies. My old version was simply:
1  
2  
3  
4  
5  
6  
private byte[] receiveData(int length) throws IOException //reading 22kb in one go, gets corrupted.
{
      byte[] data = new byte[length];
      is.read(data);
      return data;
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
private void sendData(byte[] data) //sending 22kb in one go
{
      try
      {
            os.write(data);
            os.flush();
      }
      catch (IOException e)
      {
         e.printStackTrace();
      }
}


It may have been useful to say that I am also using UDP on a different port. I know there are conflicts so I should try to minimize UDP sending while downloading data with TCP. (When the player joins the server, TCP is only used to download the server data, then UDP is used for everything else).

Thanks for the information about flushing. I really want to make sure there is no chance of corruption, since TCP is supposed to be reliable...
I read up that the maximum packet size for ethernet is 1500 bytes, do I have to worry about this, or does TCP take care of it? eg. Should I write 1024 bytes at a time and flush after each?

Roland
24  Game Development / Networking & Multiplayer / Questions about TCP sending and packet size on: 2012-09-04 12:58:38
Hello, I had a problem with TCP. My networking code works fine when I run the server and client on my pc, but when my friend tries to join the game, or I join his, the data gets corrupted and the received length is wrong when a 22kb packet is sent in one go.

I changed it so I send the tcp data one byte at a time, flushing the output stream after each byte. I guess this is quite inefficient / slow? the main thing is that now it works.

So, what is optimal? and right now, I am waiting in an infinite loop for the next byte, like so (because I know how many bytes are expected, that was sent earlier), this is bad right? is there a better way? (read() blocks anyway, but I had to put it in a loop because each time flush is called i get a -1 on the receiving end)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
private byte[] receiveData(int length) throws IOException
   {
      byte[] data = new byte[length];
     
      int offset = 0;
      while (offset < length)
      {
         int len = 1;
         
         
         int result = -1;
         do
         {
            result = is.read(data, offset, len);
         }
         while(result == -1);
         
         offset += len;
      }
     
     
     
      return data;
   }



Here's the server code

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
private void sendData(byte[] data)
   {
      try
      {
         int offset = 0;
         while (offset < data.length)
         {
           
            int len = 1;
           
            os.write(data,offset, len);
            os.flush();
            offset += len;
         }
         
      }
      catch (IOException e)
      {
         e.printStackTrace();
      }
   }


Thanks,
roland


25  Game Development / Shared Code / Re: Pre-multiplied Alpha for drawing particles in one pass on: 2012-08-21 11:12:57
Critical feature of using premult alpha: you must premultiply the alpha in all your graphics before you upload them to OpenGL! I do this at compile time but if you're lazy you can do it at runtime:
1  
2  
   BufferedImage bi = ImageIO.read(inputFile);
   bi.coerceData(true); // This forces the alpha to be premultiplied, if it isn't, and does nothing, if it already is


Cas Smiley
Shocked thanks! so what are the image backgrounds supposed to look like? (eg. black or transparent or it doesn't matter?)
26  Game Development / Shared Code / Re: Pre-multiplied Alpha for drawing particles in one pass on: 2012-08-20 10:18:29
Quote
Thanks  Smiley that sounds interesting, any chance of a screenshot or something?



I just wanted to make something to help me get a better handle on making textures, and am only starting to realize how much is involved to make a tool like this useful!

One thing I didn't realize until I just this hour, (when I made the display boxes double in size along the horizontal) is that the way I did scaling is kind of dubious. Maybe I should define my scaling in terms of a set number of pixels rather than as a proportion of the display area? But given that screen resolutions vary a lot, even that is kind of dubious as a measure. So, producing the equations as I do in the text fields below the sliders (they don't quite fit in the JTextFields visually) is maybe not so useful. Also, I suspect people don't use a translation very often.

Right now it is monochromatic and alpha isn't involved. Your post and links are very helpful in working out how to handle this once I'm ready to try including color and transparency.

Going back to the idea of adding vs lerp -- I think I still want to try that out. Right now, I am just taking a weighted average for the displayed values. But I was thinking I wanted to do something like this: specify a mapping from the noise function to a number range and then add the results in. For example, have one Simplex output mapped to values from -16 to 16, and ADD these in to get the final color value. It doesn't seem to me that there is a simple way to get the equivalent mathematical results using lerp. True?

I haven't looked around to see if there are already tools that do these graphics manipulations with the goal of creating procedural code. Nor do I know if there is much interest in such. Most people would just use an artist to get design and create the needed tiles/textures, I assume.

That's a good question. I think you should go with scaling in terms of 1.2x or something(So how it is now), but keep the image sizes the same and their dimensions correct (so they aren't stretched 2:1 sideways), and use horizontal+vertical scrollbars on each texture.

Is the mapping for each individual pixel? Could you make the number (-16 -> 16) map to a RGB colour using another algorithm such as
r = ((i +X * SOME_BIG_NUMBER) % SOME_SMALLER_NUMBER)/SOME_SMALLER_NUMBER
g = ((i+Y * SOME_BIG_NUMBER2) % SOME_SMALLER_NUMBER2)/SOME_SMALLER_NUMBER2
b = ((i+Z * SOME_BIG_NUMBER3) % SOME_SMALLER_NUMBER3)/SOME_SMALLER_NUMBER3

where X Y Z are different numbers. I still don't really know what your doing so I may have just written something completely not what you want. If that's the case, just ignore it  Grin

Sorry I don't know much about noise functions, nor much about textures apart from the very basics and a few different types of blend modes. If you manage to make a good procedural texture maker that would be awesome! Right now I use Texture Maker Professional v3.0.3  (http://www.texturemaker.com/screenshots.php) which has a lot of procedural options but its hard to make good ones (atleast for me it is)


I'm glad my code will help you out later Smiley This should be a more well known topic I think! It's important and I hadn't even heard about it until a few days ago Cranky
27  Game Development / Shared Code / Re: Pre-multiplied Alpha for drawing particles in one pass on: 2012-08-19 08:07:39
Some nice tips.

I happen to be writing a little tool for combining textures at the moment, and was just figuring out the importance of the distinction of addition vs interpolation. I implemented interpolation, but am now planning to give the addition option as well. So far, I'm able to do a simple scaling and translating in Simplex noise, and interpolate three such screens together. It's gui driven, and generates a text line for the Java Simplex 2D call that can be copied-and-pasted into a procedural routine.
Thanks  Smiley that sounds interesting, any chance of a screenshot or something?
28  Game Development / Shared Code / Pre-multiplied Alpha for drawing particles in one pass on: 2012-08-19 06:31:21
Firstly, thanks to Orangy Tang for pointing this out to me.

Tips on optimising particle drawing (Thanks to davedes) can be found here: http://www.java-gaming.org/topics/storing-adding-drawing-particles/27126/msg/242110/view.html#msg242110

Here are some tutorials on pre-multiplied alpha:  Pointing
http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Premultiplied%20alpha]]
http://blog.rarepebble.com/111/premultiplied-alpha-in-opengl/
http://www.quasimondo.com/archives/000665.php

It doesn't seem too complicated but you also need to have the right textures, otherwise it's not going to work.
Firstly, in the code:

Rather than having two blend modes that we use for drawing particles:

Additive, for fire, etc:
1  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);


And Normal(or Lerp) for smoke: (I use this blendmode for drawing everything else, it should be re-set after drawing the particles)
1  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);





Have just one:
1  
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);



Now, you have two different types of particles, smoke and fire. You need to keep track of these because they are drawn in slightly different ways.
Firstly setting the colour:

Additive(Fire):
1  
GL11.glColor4f(r*a,g*a,b*a,0);


Normal "Lerp" (Smoke)
1  
GL11.glColor4f(r*a,g*a,b*a,a);



The other part is the textures.

Additive textures must have a black background.
Normal/lerp textures have a transparent background.

Here is a sample additive texture for fire:

Here is a sample lerp texture for smoke:



If you use an additive texture with a transparent background you will get something like this(BAD):




Final results:



If I have any of this wrong, please correct me!

-roland
29  Java Game APIs & Engines / OpenGL Development / Re: Storing / Adding / Drawing particles on: 2012-08-19 06:09:00
Ok, I got pre-multiplied alpha working  Smiley I will make a tutorial on it I think
30  Java Game APIs & Engines / OpenGL Development / Re: Storing / Adding / Drawing particles on: 2012-08-18 13:55:28
I actually only really want two blendmodes at this point:
Additive, for fire, etc
1  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);


And another for smoke:
1  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);



If there's a way to just use a single blend mode that will work for both I would like to know it Smiley
otherwise I will use two lists, thanks.

I can't use point sprites because I want rotation as well Sad


Pages: [1] 2 3 ... 10
 

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 (30 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (198 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!