Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Dynamic tile map lighting.  (Read 13287 times)
0 Members and 1 Guest are viewing this topic.
Offline SkyAphid
« Reply #30 - Posted 2012-04-29 19:12:47 »



Can someone explain this?
Yes, that looks like you have mismatched lwjgl jar + source setup in eclipse. The debug info from the .class file it's running says that the function is at line 2052, but when eclipse tries to find that in the source attachment you've given it it doesn't exist.

I'd suggest upgrading your lwjgl (jars + source + docs) to the latest so you know they're all the exact same version.

I just updated all of the jars and DLLs. I don't use the sources or docs, so I leave them out. Same problem persists.

About 90% of the time though, things don't work just because I'm the one using it ;p

EDIT:
Here's my code for initializing the game window.

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  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
//Set up display
      try {
          Display.setInitialBackground(1, 1, 1);
         
            JFrame frame = new JFrame("Nusarium");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

            CanvasGameContainer container;
            container = new CanvasGameContainer(new ScalableGame(new Game(), GAME_WIDTH, GAME_HEIGHT));
            container.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT)); //NOTE: Usable 640x480
            container.getContainer().setTargetFrameRate(60);
            container.getContainer().setShowFPS(true);
           
               GL11.glViewport(0,0,GAME_WIDTH,GAME_HEIGHT);
               GL11.glMatrixMode(GL11.GL_PROJECTION);
               GL11.glLoadIdentity();
               GLU.gluPerspective(45.0f, ((float)GAME_WIDTH/(float)GAME_HEIGHT),0.1f,100.0f);
               GL11.glMatrixMode(GL11.GL_MODELVIEW);
               GL11.glLoadIdentity();
               GL11.glShadeModel(GL11.GL_SMOOTH);
               GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
               GL11.glClearDepth(1.0f);
               GL11.glEnable(GL11.GL_DEPTH_TEST);
               GL11.glDepthFunc(GL11.GL_LEQUAL);
               GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,
               GL11.GL_NICEST);
           
            if (!stretchScreen){
              GridBagConstraints c = new GridBagConstraints();
               c.fill = GridBagConstraints.CENTER;
               frame.getContentPane().setLayout(new GridBagLayout());
               frame.getContentPane().add(container, c);
            }
           
               frame.getContentPane().setBackground(java.awt.Color.black);
               frame.getContentPane().add(container);
               frame.pack();
               frame.setLocationRelativeTo(null);
               frame.setResizable(true);
               frame.setMinimumSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
               container.requestFocusInWindow();
               frame.setVisible(true);
               container.start();
           
            frame.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent we){
                Display.destroy();
                System.exit(0);
                }
            });
       
           
         } catch (SlickException ex) {
            ex.printStackTrace();
         }

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline davedes
« Reply #31 - Posted 2012-04-30 01:30:14 »

You are trying to use OpenGL before it's been initialized (this also happens when you try to render from a different thread). GL calls should be made from the same (rendering) thread.

The solution to your problem is to move your GL11 calls to your game's init() method.

Why the ScalableGame? Also, if you haven't already, be sure to update to the latest slick dev branch code. Then you can use getContainer().exit() instead of manually destroying the display/AL. I'll try to put up a tutorial on pulling dev branch code in the next couple days, and hopefully get a merge in soon so the code is downloadable in binary form on Slick's website.

Offline SkyAphid
« Reply #32 - Posted 2012-04-30 01:41:50 »

You are trying to use OpenGL before it's been initialized (this also happens when you try to render from a different thread). GL calls should be made from the same (rendering) thread.

The solution to your problem is to move your GL11 calls to your game's init() method.

Why the ScalableGame? Also, if you haven't already, be sure to update to the latest slick dev branch code. Then you can use getContainer().exit() instead of manually destroying the display/AL. I'll try to put up a tutorial on pulling dev branch code in the next couple days, and hopefully get a merge in soon so the code is downloadable in binary form on Slick's website.

Okay. Scalable is so I can resize the window, and stretch it if I want too. Weird situation. lol. It needs A LOT of fine tuning.

Anyway, since you seem to know a lot about this stuff, can you answer a question I put on here earlier?

"Well, the lighting I want is really simple. I just want black if there's no light, and circles of light where there is. If you can just point out functions in the direction of doing this, I can just kind of bullcrap my way through."

I'd appreciate it.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #33 - Posted 2012-04-30 02:32:40 »

Also, why the need for 3D perspective, depth testing, etc? Are you making a 3D game? You'll have a rough time with Slick2D if you try to integrate certain utilities (like, say, Image or ScalableGame) alongside low-level GL calls. If you plan to do 3D, I'd recommend either avoiding Slick2D altogether (instead choosing Slick-Util or a different library), or using SlickCallable to be safe. Even then, ScalableGame + GL calls will give you trouble (as it warns in ScalableGame JavaDoc).

Quote
"Well, the lighting I want is really simple. I just want black if there's no light, and circles of light where there is. If you can just point out functions in the direction of doing this, I can just kind of bullcrap my way through."
I'm just jumping into this thread now, but there are some ways to do this in Slick2D without relying on low-level OpenGL calls.

The easiest is to use an alpha map, and you won't need to worry about math or combining lights or what have you. One of the downsides to this is that it requires extra passes, which may lead you to fillrate limitations. The result is nice, though:


Is that what you're looking for? Or are you looking for a more "low-res" / retro look? e.g. In Terraria; each tile is affected.

Offline SkyAphid
« Reply #34 - Posted 2012-04-30 03:05:39 »

Also, why the need for 3D perspective, depth testing, etc? Are you making a 3D game? You'll have a rough time with Slick2D if you try to integrate certain utilities (like, say, Image or ScalableGame) alongside low-level GL calls. If you plan to do 3D, I'd recommend either avoiding Slick2D altogether (instead choosing Slick-Util or a different library), or using SlickCallable to be safe. Even then, ScalableGame + GL calls will give you trouble (as it warns in ScalableGame JavaDoc).

Quote
"Well, the lighting I want is really simple. I just want black if there's no light, and circles of light where there is. If you can just point out functions in the direction of doing this, I can just kind of bullcrap my way through."
I'm just jumping into this thread now, but there are some ways to do this in Slick2D without relying on low-level OpenGL calls.

The easiest is to use an alpha map, and you won't need to worry about math or combining lights or what have you. One of the downsides to this is that it requires extra passes, which may lead you to fillrate limitations. The result is nice, though:


Is that what you're looking for? Or are you looking for a more "low-res" / retro look? e.g. In Terraria; each tile is affected.


The game is 2D, and all the graphics are sketched out/pixel drawn by me, so I need something that would fit this:



I've consider both styles of shading, but I think the alpha map would go best. What do you think? They need to be dynamic and re-sizable on the go.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline davedes
« Reply #35 - Posted 2012-04-30 03:32:02 »

What do you mean "dynamic"? Do they need to interact with walls? (i.e. will walls affect the lighting)

Alpha maps should be easier, and resizing is just a matter of drawing the map at a different size. If I get a chance I'll throw together an example, although there should be some rudimentary code lying around slick forums already.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #36 - Posted 2012-04-30 09:13:55 »

This thread may be of interest: http://www.java-gaming.org/topics/realistic-lighting-in-a-2d-game/20161/view.html

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline SkyAphid
« Reply #37 - Posted 2012-04-30 12:17:22 »

What do you mean "dynamic"? Do they need to interact with walls? (i.e. will walls affect the lighting)

Alpha maps should be easier, and resizing is just a matter of drawing the map at a different size. If I get a chance I'll throw together an example, although there should be some rudimentary code lying around slick forums already.

I'd like walls to affect lighting, but, if it's one of those overcomplicated not worth it type deals I think I'll just go with alpha maps. Haha. I'd appreciate that example too, if you get around to it.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline davedes
« Reply #38 - Posted 2012-04-30 20:02:00 »

Eventually this will make its way into the Slick wiki. If I'm ambitious, I'll also add tutorials/code for two other examples: lighting tiles per-vertex and lighting via shaders.

The gist of the technique:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
for each light {
    set draw mode to MODE_ALPHA_MAP
    clear alpha map
    draw alpha map image at light position
   
    set draw mode to MODE_ALPHA_BLEND
    set clip (glScissor) to ignore pixels outside of the lit area
    draw tile map as per usual
    clear clip
}
set draw mode to MODE_NORMAL




Alpha maps won't be very efficient if you plan to have many lights at once (in that instance, you could improve efficiency by "baking" the lights, i.e. rendering static lights to an offscreen image). Also, the lighting won't interact with walls or corridors. If your game is very particular, you might be able to hack around with some different alpha maps to fake that "dynamic" aspect, but it would probably be easier to just use per-vertex lighting or shaders.

Code:
http://www.java-gaming.org/?action=pastebin&id=76

Sprite sheet: (right click + save as)

(credits to Lost Garden for the awesome and free ground tiles)

Offline SkyAphid
« Reply #39 - Posted 2012-04-30 22:11:36 »

Eventually this will make its way into the Slick wiki. If I'm ambitious, I'll also add tutorials/code for two other examples: lighting tiles per-vertex and lighting via shaders.

The gist of the technique:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
for each light {
    set draw mode to MODE_ALPHA_MAP
    clear alpha map
    draw alpha map image at light position
   
    set draw mode to MODE_ALPHA_BLEND
    set clip (glScissor) to ignore pixels outside of the lit area
    draw tile map as per usual
    clear clip
}
set draw mode to MODE_NORMAL




Alpha maps won't be very efficient if you plan to have many lights at once (in that instance, you could improve efficiency by "baking" the lights, i.e. rendering static lights to an offscreen image). Also, the lighting won't interact with walls or corridors. If your game is very particular, you might be able to hack around with some different alpha maps to fake that "dynamic" aspect, but it would probably be easier to just use per-vertex lighting or shaders.

Code:
http://www.java-gaming.org/?action=pastebin&id=76

Sprite sheet: (right click + save as)

(credits to Lost Garden for the awesome and free ground tiles)


I'm going to use this more than likely, but if you happen to know of any good shader tutorials that's as informative and helpful for visual learners as yours is, please do share. Haha

Thank you!

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #40 - Posted 2012-04-30 23:18:12 »

Posted the code and more details on the technique here:
http://slick.cokeandcode.com/wiki/doku.php?id=alpha_maps

Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #41 - Posted 2012-05-01 11:40:16 »


:O

:O

...

:O

I love you!

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Online pitbuller
« Reply #42 - Posted 2012-05-01 11:57:13 »

My slick2d lights in action.
http://www.youtube.com/watch?v=hCofPfqPL8w#t=1m16s

This simple code snippet draw nice lights pretty efficiently and these blend together smoothly. Light is just class that have float x, y and size. Alphamap is just like usual one http://dl.dropbox.com/u/10960490/alphamini.png
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
void lights(Graphics g) {
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);

   g.clearAlphaMap();

        for (Lights l :  lightList){
            g.scale(l.size, l.size);      
            alphamap.drawCentered(l.x, l.y);
        }

   g.resetTransform();
   GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_DST_ALPHA);
   g.fillRect(0, 0, ScreenWidth, ScreenHeight);
   g.setDrawMode(Graphics.MODE_NORMAL);
}



For full dynamic 2d lights solution I have made this http://code.google.com/p/box2dlights/
Offline SkyAphid
« Reply #43 - Posted 2012-05-02 02:14:38 »



How do I fix that?
(Not the yellow box, it's supposed to be there)

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline davedes
« Reply #44 - Posted 2012-05-02 02:31:59 »

There might be a way using Slick's blending modes, but the simplest would be to bake your sprites/overlays/etc onto the same texture (via offscreen images), and only apply the lighting as if it were a "post processing" effect.

There are some more flexible lighting solutions discussed here, although all of them require some OpenGL tinkering:
http://www.java-gaming.org/topics/starbound-lighting-techneques/26363/msg/230908/view.html#msg230908

Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #45 - Posted 2012-05-02 02:35:52 »

Should the player background be filled with alpha, so the player blends right in?

Offline SkyAphid
« Reply #46 - Posted 2012-05-02 02:37:22 »

Should the player background be filled with alpha, so the player blends right in?
Yes.

Edit: Also..I need a better way of handling these lights. I need to draw them kind of in-between blending, instead of before blending. If I do it before blending, it really makes the engine unflexible and messy. If I need to use OpenGL I'm completely fine with it, I just need someone to explain it in relatively simple terms.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Pages: 1 [2]
  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.

rwatson462 (32 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (58 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!