Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
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]
1  Game Development / Newbie & Debugging Questions / Re: [LWJGL] problem with alpha texture and GL_LINEAR rendering on: 2014-05-07 15:32:21
Yeah ! Excellent, now I know all that I needed to rule the gaming world, thanks !!! mouhahahahaha Grin
2  Game Development / Newbie & Debugging Questions / Re: [LWJGL] problem with alpha texture and GL_LINEAR rendering on: 2014-05-07 15:07:24
Thanks a lot!

I just tested this solution and it's perfect to remove any artifact inside a bloc with abrupt alpha jumps !

However, I still have the problem with the blocs' borders.
It's obvious that when the texture of a bloc is scaled, its last line is interpolated with its first line, and its last column with its first one.
Is there anything I can do about this ?
3  Game Development / Newbie & Debugging Questions / [LWJGL] problem with alpha texture and GL_LINEAR rendering on: 2014-05-07 12:03:23
Hello!

I'm using lwjgl to render a 2D scene. The map is based on blocks referencing textures.

here is the init code for orthographic view and alpha channel;
1  
2  
3  
4  
5  
6  
7  
8  
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, W, H, 0, 1, -1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);      

      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);


the textures are loaded (then all mipmap levels are generated), they have the following parameters:
1  
2  
3  
4  
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, w, h, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);


I tried the alternatives to LINEAR and LINEAR_MIPMAP_LINEAR modes with NEAREST but so far I see rendering artifacts when the textures are scaled (zoom in or out).

Here are some examples of what I get with linear interpolation:



These are some basic textures with a strong zoom. As you can see there are artifacts on the border of the bloc, a dark semi-transparent line which comes from a pixel mix with the opposite side of the texture (dark lines can also be seen at the transition between opaque and transparent zones but are less problematic). I checked that the original textures do not include those artifacts.

So the default linear pixel mixing openGL function really does not seem appropriate to just draw scaled alpha textures Huh Isn't that weird ? Is there a solution to remove those unwanted lines ? Does it require some GLSL code or is there a standard method ? (Would the result be the same if I used a 3D projection matrix instead of an orthogonal one ?)

Thanks for reading Smiley
4  Game Development / Newbie & Debugging Questions / Re: Direct 2D pixels manipulation on: 2013-10-11 11:11:29
Sounds great ! Do you have any example / link available on this subject ? (Trust me I tried to find it but I'm completely lost right now)
5  Game Development / Newbie & Debugging Questions / Direct 2D pixels manipulation on: 2013-10-11 09:54:37
Hello, I recently started to search for high FPS 2D screen pixels manipulation, and realized I needed something faster than java2D. The big bottleneck is the permanent transfer between cpu memory and video card memory, especially for a full screen high resolution buffer. Until recently I worked on a 2D/3D creation software. It didn't need high FPS but needed high quality and totally pixel controlled results (for the 2D creation part). I see in many posts that direct pixel manipulation is kind of discouraged by experienced posters. Well for now I would like to manipulate pixels anyway, and later learn other ways to do fast rendering. But I didn't find a very clear example that does just that. I'm a little lost with the PBO / pbuffers /frame buffers usage. Here is a short class that just draws a random color on each pixel and shows FPS for java2D.

My question is what would be the equivalent code if I used LWJGL?

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  
56  
57  
58  
59  
60  
61  
62  
import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.ImageCapabilities;
import java.awt.BufferCapabilities.FlipContents;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.util.Random;

import javax.swing.JFrame;

public class Test
{ private final static GraphicsDevice screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
  private final static Random random = new Random(System.currentTimeMillis());

  public static void main(String[] args)
  { System.setProperty("sun.java2d.opengl", "true");
    final JFrame f = new JFrame("TEST");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setUndecorated(true);
    f.setResizable(false);
    f.setIgnoreRepaint(true);
    screen.setFullScreenWindow(f);
    f.addKeyListener(new KeyListener()
    { public void keyPressed(KeyEvent e) {System.exit(0);}
      public void keyReleased(KeyEvent e) {}
      public void keyTyped(KeyEvent e) {}
    });
    final int w = f.getWidth(), h = f.getHeight();
    try {f.createBufferStrategy(2, new BufferCapabilities(new ImageCapabilities(true), new ImageCapabilities(true), FlipContents.UNDEFINED));}
    catch (AWTException e) {e.printStackTrace();}
    final BufferStrategy s = f.getBufferStrategy();
    final BufferedImage img = screen.getDefaultConfiguration().createCompatibleImage(w, h);
    final int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
    long time = 0, frames = 0;
    final long start = System.currentTimeMillis();
    while (true) try
    { final Graphics g = s.getDrawGraphics();
      for (int k = w*h; k-->0;) pixels[k] = random.nextInt();
      g.drawImage(img, 0, 0, null);
      time = System.currentTimeMillis()-start;
      frames++;
      if (time>0)
      { String m = "FPS : "+(frames*1000.0/time); int sw = g.getFontMetrics().stringWidth(m);
        g.setColor(Color.BLACK); g.fillRect((w-sw)/2, h/2-20, sw, 30);
        g.setColor(Color.WHITE); g.drawString(m, (w-sw)/2, h/2);
      }
      s.show();
      g.dispose();
    }
    catch (Exception e)
    { e.printStackTrace();
      System.exit(0);
    }
  }
}
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (75 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!