Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Rendering glitch with multiple cubes + aliasing  (Read 1173 times)
0 Members and 1 Guest are viewing this topic.
Offline Geek_Link

Senior Newbie





« Posted 2013-12-11 20:06:00 »

I have a map of 3D cubes and everything seems good except for two things.

First I have a problem that when I move my VBO of block up and down I get at some places little lines that flicker when I move.
https://www.youtube.com/watch?v=Jhd0jDB1Nr8

The other problem I have Is about aliasing  some textures flicker allot. 
https://www.youtube.com/watch?v=jKCdQvWBYXE

I know I can fix this one using linear filter for my texture but the problem is that the linear filter cause texture bleeding since it blend the closest colors together or something like that. glShadeModel(GL_SMOOTH) or changing the pixelformat of LWJGL isnt helping since the problem is texture based and not polygon based.

One last thing, if I change the pixel format for anything else than 0 I get again little lines between my cubes I don't know if this one I a texture bleeding problem too.
http://postimg.org/image/i3a6bller/

--Ps I dont wan't to use shaders if possible. I in the range of the possible I don't want to limit old computers.
Online trollwarrior1
« Reply #1 - Posted 2013-12-11 20:09:13 »

Try enabling vsync. Should fix some flickering.
Offline Geek_Link

Senior Newbie





« Reply #2 - Posted 2013-12-11 20:15:21 »

Thank you for your answer but vsync is already enabled.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2013-12-11 23:00:50 »

Texture bleeding. Use GL_NEAREST. Is your texture power of 2? Are you using mipmaps?

Myomyomyo.
Offline Geek_Link

Senior Newbie





« Reply #4 - Posted 2013-12-12 03:57:28 »

No I don't use mipmaps and I don't know how to implement them. would it be a good idea for only tiles ??

yes I use power of two textures 512*512 for my tiles of 32 pixel.
Offline theagentd
« Reply #5 - Posted 2013-12-12 18:54:06 »

Hmm... Can we see some code?

Myomyomyo.
Offline Meanzie

Innocent Bystander





« Reply #6 - Posted 2013-12-12 23:08:48 »

Not that I am an expert, but I somehow seem to associate this with depth issues.
Do you have depth testing enabled? And if you do have depth testing enabled,
Do you have two faces exactly on top of each other?

I might be wrong here, but I think it's worth checking out.
Offline Geek_Link

Senior Newbie





« Reply #7 - Posted 2013-12-13 03:37:39 »

I have not yet optimized my map yes there's  faces at the same place it will probably fix some problems but is there a solution for the texture aliasing since gl linear create texture bleeding?
Ps yes dept testing is enabled.
Pps . sorry I'm on my phone.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #8 - Posted 2013-12-13 03:51:33 »

Not that I am an expert, but I somehow seem to associate this with depth issues.
Do you have depth testing enabled? And if you do have depth testing enabled,
Do you have two faces exactly on top of each other?

I might be wrong here, but I think it's worth checking out.
If he didn't have depth testing enabled all you would see is a bunch of vertices rendered in front of each other. Depth testing should not affect texture bleeding. I agree, show us some code.

Offline Geek_Link

Senior Newbie





« Reply #9 - Posted 2013-12-13 04:06:55 »

what I think is important in the main
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  
public void init(){
      try {
         PF = new PixelFormat(8, 16, 0, 16);
         Display.setDisplayMode(new DisplayMode(width, height));
         Display.setVSyncEnabled(true);
         Display.create(PF);
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
      lastFps = getTime();
      setupGL();
      screen.init();
      splashscreen.init();
   }

public void setupGL(){
      glMatrixMode(GL_PROJECTION);
      //glOrtho(0, width, height, 0, 1, -1);
     glViewport(0, 0, Display.getWidth(), Display.getHeight());
      gluPerspective(50f, (float)800 / (float)600, 1, 1000);

      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glRotatef(-35f, 1.0f, 0.0f, 0.0f);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
      glEnable(GL_TEXTURE_2D);
     
   }



my vbo class I know Its a mess sorry
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  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
public class Quad3DVBO extends VBO{

   protected int instances = 0;
   
   public Quad3DVBO(){
     
   }
   
   public Quad3DVBO(Color color){
      this.color = color;
      colored = true;
      numberOfID += 1;
   }
   
   public Quad3DVBO(SpriteSheet sheet, Textures texture){
      this.sheet = sheet;
      this.texture = texture;
      textured = true;
      numberOfID += 1;
   }
   
   public void add(float[] coords){
      setVertices(coords);

      if(colored){
         setColors();
      }
     
   }
   
   public void add(Block block){
     
      for(float[] v : block.getVerices()){
         
         setVertices(v);
         
         if(colored){
            setColors();
         }
         
         if(textured){
            setTextures();
         }
      }
   }
   
   public void add(Block block, float x, float y, float z){
      for(float[] v : block.getVerices(x, y, z)){
         setVertices(v);
      }
         if(colored){
            setColors();
         }
         
         
      for(float[] t  : block.getTextures()){
         if(textured){
            setTextures(t);
         }
      }
         
   }
   
   public void add(float[] coords, float[] cols){
      setVertices(coords);
      if(colored){
         setColors(cols);
      }
   }
   
   public void init() {
      buffIds = BufferUtils.createIntBuffer(numberOfID);
      glGenBuffers(buffIds);
      vertexId = buffIds.get(0);
      indexId = buffIds.get(1);
      if(colored){
         colorId = buffIds.get(2);
      }
      if(textured){
         textureCoordsId = buffIds.get(2);
      }
     
         vertexBuff = BufferUtils.createFloatBuffer(12*instances);
         for(float[] v : vertices){
            vertexBuff.put(v);
         }
         
         indexBuff = BufferUtils.createShortBuffer(6*instances);
         for(short[] i : indices){
            indexBuff.put(i);
         }
         
         if(colored){
            colorBuff = BufferUtils.createFloatBuffer(16*instances);
           
            for(float[] c : colors){
               colorBuff.put(c);
            }
           
            colorBuff.flip();
            glBindBuffer(GL_ARRAY_BUFFER, colorId);
            glBufferData(GL_ARRAY_BUFFER, colorBuff,  GL_STATIC_DRAW);
            glBindBuffer(GL_ARRAY_BUFFER, 0);
         }
         
         if(textured){
            textureBuff = BufferUtils.createFloatBuffer(8 * instances);
           
            for(float[] t : textures){
               textureBuff.put(t);
            }
           
            textureBuff.flip();
            glBindBuffer(GL_ARRAY_BUFFER, textureCoordsId);
            glBufferData(GL_ARRAY_BUFFER, textureBuff,  GL_STATIC_DRAW);
            glBindBuffer(GL_ARRAY_BUFFER, 0);
         }
         
         vertexBuff.flip();
         glBindBuffer(GL_ARRAY_BUFFER, vertexId);
         glBufferData(GL_ARRAY_BUFFER, vertexBuff,  GL_STATIC_DRAW);
         glBindBuffer(GL_ARRAY_BUFFER, 0);
         
         indexBuff.flip();
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);
         glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBuff, GL_STATIC_DRAW);
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
   }

   public void render() {
     
      glPushMatrix();
      //glShadeModel(GL_SMOOTH);
     if(textured){
         glBindTexture(GL_TEXTURE_2D, sheet.getTextureID());
      }
      glCullFace(GL_FRONT);
      glTranslatef(x, y, z);
      glEnableClientState(GL_VERTEX_ARRAY);
      glBindBuffer(GL_ARRAY_BUFFER, vertexId);
      glVertexPointer(3, GL_FLOAT, 0, 0);
         if(colored){
            glEnableClientState(GL_COLOR_ARRAY);
            glBindBuffer(GL_ARRAY_BUFFER, colorId);
            glColorPointer(4, GL_FLOAT, 0, 0);
         }
         if(textured){
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glBindBuffer(GL_ARRAY_BUFFER, textureCoordsId);
            glTexCoordPointer(2, GL_FLOAT, 0, 0l);
         }
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);
         glDrawElements(GL_TRIANGLES, indexBuff.capacity(), GL_UNSIGNED_SHORT, 0);
         glBindBuffer(GL_ARRAY_BUFFER, 0);
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
         if(colored){
            glDisableClientState(GL_COLOR_ARRAY);
         }
         if(textured){
            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
         }
      glDisableClientState(GL_VERTEX_ARRAY);
      if(textured){
         glBindTexture(GL_TEXTURE_2D, 0);
      }
      glPopMatrix();
   }

   public void dispose(){
      buffIds.put(0, vertexId);
      buffIds.put(1, indexId);
      if(colored){
         buffIds.put(2, colorId);
      }
      if(textured){
         buffIds.put(2, textureCoordsId);
      }
      glDeleteBuffers(buffIds);
   }
   
   public void translate(float x, float y, float z){
      this.x += x;
      this.y += y;
      this.z += z;
   }
   
   
   
   
   
   
   
   
   
   
   private void setVertices(float[] vert){
      if(vert.length == 12)
      {
         short indpos = (short)(instances*4);
         vertices.add(vert);
         indices.add(new short[]{(short)(indpos+2), (short)(indpos+1), indpos, indpos, (short)(indpos+3), (short)(indpos+2)});
         instances++;
      }else{
         System.out.println("ERROR - The array must containt 12 variables.");
      }
   }
   
   private void setColors(){
      float[] vertexCols = new float[16];
      float[] toArray = color.getColors();
      for(int i = 0; i <= 3; i++){
         vertexCols[i*4] = toArray[0];
         vertexCols[i*4+1] = toArray[1];
         vertexCols[i*4+2] = toArray[2];
         vertexCols[i*4+3] = toArray[3];
      }
      colors.add(vertexCols);
   }
   
   private void setColors(float[] cols){
      float[] vertexCols = new float[16];
      for(int i = 0; i <= 3; i++){
         vertexCols[i*4] = cols[0];
         vertexCols[i*4+1] = cols[1];
         vertexCols[i*4+2] = cols[2];
         vertexCols[i*4+3] = cols[3];
      }
      colors.add(vertexCols);
   }
   
   private void setTextures(){
      float[] toArray = texture.getCoords();
   
      textures.add(toArray);
   }
   
   private void setTextures(float[] coords){

      textures.add(coords);
   }

}


initializing my sprite sheet
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public void init(){
      textureID = glGenTextures();
      glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
       
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);


        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
       
       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
       glBindTexture(GL_TEXTURE_2D, 0);
       
   }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #10 - Posted 2013-12-13 04:15:37 »

Unrelated, but i strongly recommend against have a buffer object for every cube, which it seems you are doing right now. And to be honest, buffer objects aren't that great for this type of geometry anyway. Use vertex arrays or even display lists, if you're ok with using deprecated GL.
Edit: Never mind it seems like thats how you render chunks. I also found something else, glTranslatef. Don't use this for moving your chunks when you can just specify starting coordinates for the chunk and pass over expensive matrix calls..

Offline Geek_Link

Senior Newbie





« Reply #11 - Posted 2013-12-13 04:53:40 »

I also found something else, glTranslatef. Don't use this for moving your chunks when you can just specify starting coordinates for the chunk and pass over expensive matrix calls..

But how can I move my vbos then?

Quote
and pass over expensive matrix calls..

What do you mean?
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #12 - Posted 2013-12-13 05:01:27 »

If you have static chunks, why would you ever translate them using more expensive matrix math when you can simply set a start point for your chunk, and then send the vertices to your renderer along with the chunk offset?

Offline Geek_Link

Senior Newbie





« Reply #13 - Posted 2013-12-13 05:23:59 »

Quote
If you have static chunks, why would you ever translate them using more expensive matrix math when you can simply set a start point for your chunk, and then send the vertices to your renderer along with the chunk offset?
Because the map has to move when the player is moving to to make the "camera effect" ??

I don't know if it can help but I definitely get texture bleeding with pixel format other than 0.
http://s24.postimg.org/ffo13rrwh/Untitled.png
Offline theagentd
« Reply #14 - Posted 2013-12-13 15:04:12 »

If you have static chunks, why would you ever translate them using more expensive matrix math when you can simply set a start point for your chunk, and then send the vertices to your renderer along with the chunk offset?
This is irrelevant. Default OpenGL automatically precomputes the gl_ModelViewProjectionMatrix, so it's still just a single matrix multiplication for the GPU.

I don't know if it can help but I definitely get texture bleeding with pixel format other than 0.
You're creating your pixel format using
new PixelFormat(8, 16, 0, 16);
. That's 8 bits of alpha (not really usable for 3D), 16 bits of depth and 16 samples per pixel. 16x multisampling isn't supported by any hardware, but on Nvidia hardware at least 16x multisampling is mapped to 2x2 supersampling (double resolution rendering) plus 4x multisampling. It's the most expensive anti aliasing setting you can enable from OpenGL, around 4x to 8x as expensive as no multisampling. Not only is it expensive, it's also screwing up your texture coordinates.

Multisampling works by computing the color of a pixel once, but computing depth and coverage for each sample. With 4x MSAA you get the following layout. The green point is the point for which the color is computed.

At edges only some of the 4 samples will be covered by the triangle. Consider a triangle that barely overlaps the pixel's top (red) sample but not the green center point. Despite the fact that the green center point isn't covered, the color will be calculated as if it was covered, but the result will only be written to the top sample. That means that all the vertex attributes, including texture coordinates and colors, will be extrapolated (as opposed to interpolated when the triangle covers the center point), and the texture coordinates generated can be outside the range that the vertices specify. When using sprite sheets, it essentially introduces a new source of texture bleeding.

Solutions:
 - Like you said, disable all multisampling:
new PixelFormat(8, 16, 0, 0);

 - If you're okay with using shaders and OpenGL 3, create a custom texture coordinate varying and set its interpolation qualifier to centroid to prevent extrapolation.
 - Use a 2D texture array with one sprite per layer instead of a sprite sheet. Since that'll prevent all texture bleeding between sprites you can use everything from bilinear filtering and mipmaps to multisampling without any bleeding.

Myomyomyo.
Offline Geek_Link

Senior Newbie





« Reply #15 - Posted 2013-12-13 18:58:43 »

Quote
Like you said, disable all multisampling: new PixelFormat(8, 16, 0, 0);
Thats kinda sad.

Quote
If you're okay with using shaders and OpenGL 3
I'm not, at least for a global solution. I will probably implement them for peoples that suport opengl 3+ but I want a solution for those who don't support opengl3 + and shaders seems to be an other world that I haven't discovered yet.

Quote
- Use a 2D texture array with one sprite per layer instead of a sprite sheet. Since that'll prevent all texture bleeding between sprites you can use everything from bilinear filtering and mipmaps to multisampling without any bleeding.
I know that recent GFXcards have some magic way to play with texture array that doesn't make them slow but isn't a bad solution for older GFXcards?
Offline theagentd
« Reply #16 - Posted 2013-12-13 20:07:06 »

Texture arrays shouldn't be slower than normal textures. The filtering cost is exactly the same. The only difference is the amount of data you can sample from, which isn't any worse than when using 3D textures which have been supported since forever. Sadly texture arrays are just like the centroid interpolation qualifier limited to OGL3 hardware. In other words, you can't have accurate antialiasing with sprite sheets used as you use them. Traditional 3D textures can also be used, but they won't handle mipmaps correctly since they'll blend between layers as well. You could add a border with the same color as the edge pixels of each sprite, but that won't help if you're using mipmaps.

As you can see, there's no perfect solution without OGL3. You can get two of three of mipmaps, antialiasing and filtering. If you're willing to forsake mipmaps (which will look like crap when the sprites are small on the screen), you can use 3D textures or add borders around the sprites in the sprite sheet.

Myomyomyo.
Offline Geek_Link

Senior Newbie





« Reply #17 - Posted 2013-12-15 07:29:45 »

I decided to add a border around the sprites but I am wondering something let say I have a 512X512 spritesheet would it make slower if I add the border around every sprites while loading. I'm guessing Ill have to make every sprites 2X2 pixel smaller so my texture is a power of two. Do you think this is a good idea if I double the pixels for every edges of the sprites instead of doing this manualy when putting them into the bytebuffer?
Offline lcass
« Reply #18 - Posted 2013-12-15 10:32:41 »

I have had this issue and I had it from rounding to early , check you are using doubles for your positioning not integers, round too early is easy to do.
Offline theagentd
« Reply #19 - Posted 2013-12-15 11:29:38 »

I decided to add a border around the sprites but I am wondering something let say I have a 512X512 spritesheet would it make slower if I add the border around every sprites while loading. I'm guessing Ill have to make every sprites 2X2 pixel smaller so my texture is a power of two. Do you think this is a good idea if I double the pixels for every edges of the sprites instead of doing this manualy when putting them into the bytebuffer?
When you add the border is largely irrelevant. The only thing it affects is load time. Nowadays GPUs don't require power-of-2 textures, but if you decide to make your sprites 2 pixels smaller to fit the border you'll need to adjust your texture coordinates so that they don't include the border.

Myomyomyo.
Pages: [1]
  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.

Grunnt (15 views)
2014-09-23 14:38:19

radar3301 (14 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (75 views)
2014-09-10 13:57:51

TehJavaDev (105 views)
2014-09-10 06:39:09
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!