/**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. :
Video recorded on my cellphone for my view. :
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.
[spoiler]
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;
}
}
[/spoiler]
Screen class.
[spoiler]
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();
}
}
[/spoiler]
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!