Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
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 3 ... 10
 1 
 on: 2017-10-19 11:01:46 
Started by BurntPizza - Last post by Emmsii
I've managed to get myself a software developer apprenticeship! Its not Java though, its C#; but learning Java in my spare time has helped me with the basics of C# as they are fairly similar.

 2 
 on: 2017-10-19 09:57:03 
Started by BurntPizza - Last post by Stampler
Finished my first ever blog post: Asset Loading in LibGDX
Our website is not yet finished, so don't judge Wink

 3 
 on: 2017-10-19 08:51:29 
Started by dime26 - Last post by princec
spam....

Cas Smiley

 4 
 on: 2017-10-19 08:44:16 
Started by dime26 - Last post by MaryMiller86
my twit @AprilRussell710

 5 
 on: 2017-10-18 22:10:45 
Started by orange451 - Last post by orange451
I've found an interesting problem. Not sure if it's due to my own incompetence or an issue with LuaJ...

If I define a class with a metatable such as this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
// Setup Vector class
LuaValue vectorClass = CoerceJavaToLua.coerce(Vector3Lua.class);
globals.set("Vector3", vectorClass);

// Metatable stuff for Vector3
LuaTable t = new LuaTable();
t.set("__add", new TwoArgFunction() {
   public LuaValue call(LuaValue x, LuaValue y) {
      System.out.println("TEST1: " + x);
      System.out.println("TEST2: " + y);
      return x;
   }
});
t.set("__index", t);
vectorClass.setmetatable(t);


And then in lua I create an instance of "Vector3Lua":
1  
2  
3  
print( "Vector3 Metatable:", getmetatable(Vector3) );
local test1 = Vector3.new(9, 8, 7);
print("Test1 Metatable:", getmetatable(test1));


Vector3 contains a metatable, but Test1 does not. So what seems to be happening is that metatables do not pass from parents to their children from the .new() lua function. But I've seen this done before in other game engines. Hmm.

 6 
 on: 2017-10-18 18:47:38 
Started by dime26 - Last post by philfrei
didn't notice this thread until just now

@PFreihofner

 7 
 on: 2017-10-18 11:53:12 
Started by Jakibah - Last post by Abuse
For drawing a single pixel onto an accelerated surface, drawLine is faster than fillRect.

However if per pixel stuff is *all* the drawing you're doing, then do it on an unaccelerated surface direct to the image's backing int [] (exposed via DataBufferInt.getData() )

Though without hardware acceleration it's still going to be comparatively very slow; if you want to do stuff at the per pixel level, don't use Java2D.

You might be able to achieve a similar lighting effect while keeping your surfaces accelerated, but you're constrained to the composition rules defined in AlphaComposite. (The useful ones being dst_in for overlaying shadow, and src_over for applying colour). There are tutorials around on how to do this.
Though without a means of doing additive blending, you'll eventually hit a wall in what you can achieve.

Frustratingly JavaFX offers several useful (and hardware accelerated) blend modes not available in Java2D(including additive blending), but hides them behind a fundamentally flawed API design rendering them useless for the common use case.

 8 
 on: 2017-10-18 10:28:33 
Started by Jakibah - Last post by CommanderKeith
As Cas says, and you may also want to try drawing the whole image, then drawing the lights as an image with alpha over the top. That way the hardware acceleration might help if it's available.
Caching unchanged data to avoid recalculating things could also help perhaps.

 9 
 on: 2017-10-18 10:22:48 
Started by Jakibah - Last post by princec
Well firstly swap the order of traversal of image - memory is laid out horizontally so scan across before going up, not up before across.
Secondly you're going to get O(n^2) performance as you add lights.
Thirdly you appear to be reading from a BufferedImage and then fillRecting graphics of the same size a single pixel at a time! I'm amazed you even got 12fps.

What does the final output look like? I bet what you want to do is much easier than you think.

Cas Smiley

 10 
 on: 2017-10-18 10:01:16 
Started by Jakibah - Last post by Jakibah
So I started a project and my goals is to make it run on all computers (Even potatos).
But I already got an (unexpected) problem after I finished my draw method.

I am drawing a grid of 100 tile (each 32*32). And I am getting an fps of 12.

I run this method once when the program starts.

1  
2  
3  
4  
public static void Prepare() {
      Main.canvas.createBufferStrategy(2);
                //Also tested with 3
   }


Then I run this at the begin of each frame.

1  
2  
3  
4  
5  
6  
7  
public static void StartDrawing() {
      buffer = Main.canvas.getBufferStrategy();
      g = buffer.getDrawGraphics();
      g.setColor(new Color(0, 0, 0));
      g.fillRect(0, 0, Main.canvas.getWidth(), Main.canvas.getHeight());
     
   }


Then I draw everything with this method.

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  
public static void DrawTex(BufferedImage image, int x, int y, boolean lighted) {
      for (int i = 0; i < image.getWidth(); i++) {
         for (int j = 0; j < image.getHeight(); j++) {
            int color = image.getRGB(i, j);
           
            int red = (color & 0x00ff0000) >> 16;
            int green = (color & 0x0000ff00) >> 8;
            int blue = (color & 0x000000ff);
            int alpha = (color>>24) & 0xff;
            if(lighted){
               int lamp = 0;
               for(Light l : Main.app.lights){
                  int xdist = x+i-l.getX();
                  int ydist = y+j-l.getY();
                 
                  if(xdist >  -l.getRadius() && xdist < l.getRadius()){
                     if(ydist >  -l.getRadius() && ydist < l.getRadius()){
                        lamp = lamp + l.getBrightness();
                     }
                  }
               }
               red = red - Light.getDayLight() + lamp;
               green = green - Light.getDayLight() + lamp;
               blue = blue - Light.getDayLight()+ lamp;
               
               if(red < 0){
                  red = 0;
               }
               if(green < 0){
                  green = 0;
               }
               if(blue < 0){
                  blue = 0;
               }
            }
            Color c = new Color(red, green, blue, alpha);
            g.setColor(c);
            g.fillRect((i + x) - Player.getX() + Main.canvas.getWidth() / 2 - 16, (j + y) - Player.getY() + Main.canvas.getHeight() / 2 - 16, 1, 1);
           
         }
      }
   }


And at the end of the frame Irun this method.

1  
2  
3  
4  
public static void Output(){
      g.dispose();
      buffer.show();
   }


How can I make this more optimal?

Pages: [1] 2 3 ... 10
 
Ecumene (50 views)
2017-09-30 02:57:34

theagentd (76 views)
2017-09-26 18:23:31

cybrmynd (183 views)
2017-08-02 12:28:51

cybrmynd (181 views)
2017-08-02 12:19:43

cybrmynd (188 views)
2017-08-02 12:18:09

Sralse (195 views)
2017-07-25 17:13:48

Archive (745 views)
2017-04-27 17:45:51

buddyBro (879 views)
2017-04-05 03:38:00

CopyableCougar4 (1428 views)
2017-03-24 15:39:42

theagentd (1318 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!