Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
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  
  [Fixed by quew8] - LWJGL OpenGL moving quad issue.  (Read 357 times)
0 Members and 1 Guest are viewing this topic.
Offline Geek_Link

Senior Newbie





« Posted 2013-11-16 09:31:56 »

/**This isn't the final state of anything so don't judge my coding style. No, for now I am not using VBO but I definitely will. I am a native french speaker from Quebec in Canada, so do not expect me to have the perfect English skills(But feel free to nicely comment on it).
*/

Hello java game developers. I am making my own game engine using LWJGL and Slick_Util. I am still learning allot so obviously Bugs/issues are parts of the learning process. The main issue I am having is that when I move an OpenGl quad, using glTranslatef or by changing the values of the vertices I get rendering glitches that I can personally see on my screen but not on a recording  software(Here Fraps). For you,  I've uploaded on Youtube two videos, one recorded using Fraps and one using my cellphone so you can see as I do.

Video using recording software. In Youtube full screen a glitch is still there. When the quad is moving you can see a blurred line following the quad. :
https://www.youtube.com/watch?v=UD-sPkBORuk
Video recorded on my cellphone for my view. :
http://www.youtube.com/watch?v=YKq416_INP0

What do you think, is it because of my screen, graphics card or something else, and what do you think I should do to fix it?
Here are the codes for my Draw and Screen classes in case it isn't my computers fault.

Draw class.

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  
package com.willchange.nexus.graphics.drawing;
import static org.lwjgl.opengl.GL11.*;


public class Draw {
   public static final int QUAD = 1;
   public static final int LINE = 2;
   public static final int TRIANGLE = 3;
   protected int shape;
   protected int width;
   protected int height;
   protected int x;
   protected int y;
   protected int movex;
   protected int movey;
   protected float r;
   protected float g;
   protected float b;
   protected float a;
   


   public Draw(int shape, int width, int height, int x, int y){
      this.shape = shape;
      this.width = width;
      this.height = height;
      this.x = x;
      this.y = y;
      r = 1;
      g = 1;
      b = 1;
      a = 1;
   }
   
   public void update(int delta){
     
   }
   
   public void render(){
      switch(shape){
      case 1 :
         glPushMatrix();
      glTranslatef(x, y, 0);
      glBegin(GL_QUADS);
      glColor4f(r,g,b,a);
      glVertex2i(width,height);
      glVertex2i(0,height);
      glVertex2i(0,0);
      glVertex2i(width,0);
      glEnd();
              glPopMatrix();
      break;
      }

   }
   
   public void move(int x, int y){
      this.x += x;
      this.y += y;
   }
   
   //setters
  public int getWidth(){return width;}
   public int getHeight(){return height;}
   public int getX(){return x;}
   public int getY(){return y;}
   //getters
  public void setX(int x){this.x = x;}
   public void setY(int y){this.y = y;}
   public void setColor(int r, int g, int b, int a){
      this.r = (float) r / 255f;
      this.g = (float) g / 255f;
      this.b = (float) b / 255f;
      this.a = (float) a / 255f;
   }
}


Screen class.

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  
package com.willchange.nexus.graphics.screens;

import static org.lwjgl.opengl.GL11.*;


import java.util.ArrayList;
import java.util.List;

import com.willchange.nexus.Core;
import com.willchange.nexus.graphics.drawing.Draw;
import com.willchange.nexus.input.Input;
import com.willchange.nexus.input.KeyboardIn;

public class Screen {
   
   Input input = new KeyboardIn();
   private int width;
   private int height;
   private int x;
   private int y;
   private int movex = 0;
   private int movey = 0;
   private List<Screen> screens = new ArrayList<Screen>();
   private Draw BG;
   private Draw quad;
   
   public Screen(int width, int height, int x, int y)
   {
     
      this.width = width;
      this.height = height;
      this.x = x;
      this.y = y;
      BG = new Draw(Draw.QUAD, width, height, x, y);
      quad = new Draw(Draw.QUAD, 50, 50, x+30, y+30);
      quad.setColor(23,43,23,255);
   }
   
   public void init(){
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, width, height, 0, 1, -1);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
   }
   
   public void update(int delta){
      input.update(delta);
      movex = 0;
      movey = 0;
      int speed = 6;
     
      if(input.up){
         movey = -speed;
      }
      if(input.down){
         movey = speed;
      }
      if(input.left){
         movex = -speed;
      }
      if(input.right){
         movex = speed;
      }
      //quad.move(movex, movey);
     quad.move(movex, movey);
      quad.update(delta);
   }
   
   public void render(){
      glClear(GL_COLOR_BUFFER_BIT);
     
      BG.render();
      quad.render();
     
   }
}

and I have some questions for you guys.
-What is the best way to move shapes in OpenGL, using glTraslate or directly changing the values of the vertices.
-Is there a difference between calling the glPushMatix/glBegin every time I draw a quad and once for all the quad I am rendering.


Thank you! If you can get me valuable answers, I will love you for ever! Cheesy
Offline quew8

JGO Coder


Medals: 29



« Reply #1 - Posted 2013-11-16 12:52:24 »

Try turning on VSync with Display.setVSyncEnabled(). (I don't think that's actually the method but it's called something like that and it is in the Display class). VSync is a hardware thing (so LWJGL cannot guarantee that it'll work) which stops "tearing" on the screen. Tearing happens when the pixels of the monitor are not updated simultaneously and VSync is meant to stop that happening. Emphasis on "meant to".
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.

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

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

TehJavaDev (64 views)
2014-09-10 06:39:09

Tekkerue (32 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (29 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (36 views)
2014-09-04 23:08:59
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!