Show Posts
|
|
Pages: [1] 2 3 4
|
|
2
|
Java Game APIs & Engines / Engines, Libraries and Tools / libgdx mipmap render-problems [solved]
|
on: 2013-03-27 01:59:57
|
Hi, because it seems that I have to write it on my own: http://code.google.com/p/libgdx/issues/detail?id=1257&thanks=1257&ts=1360713176I would like to know, if the error (lines between tiles and the color of the ray):  could be caused by the missing of the edge-padding. In addition I have now clue how to add this/write that pull request. atlas-code: 1 2 3 4 5 6 7 8 9
| PixmapPacker packer = new PixmapPacker(2048, 2048, Format.RGBA8888, 5, true); Pixmap pixmap; for (int i = 0; i < levelTextures.length; i++) { pixmap = new Pixmap(Gdx.files.external(levelTextures[i])); packer.pack(levelTextures[i], pixmap); } RessourceManager.atlas = packer.generateTextureAtlas( TextureFilter.MipMapLinearNearest, TextureFilter.Nearest, true); |
for rendering I am using spritebatch + sprites (sprite(Textureregion from the atlas)). edit: if I don't use mipmaps: 1 2
| RessourceManager.atlas = packer.generateTextureAtlas( TextureFilter.Nearest, TextureFilter.Nearest, false); |
the error doesn't appear, but I would like to use mipmaps -> how to fix it? edit2: thx to ocirne  changed: 1 2 3 4 5
| new PixmapPacker(2048, 2048, Format.RGBA8888,0, false);
packer.generateTextureAtlas( TextureFilter.Nearest, TextureFilter.Nearest, true); |
best reg.
|
|
|
|
|
3
|
Java Game APIs & Engines / OpenGL Development / Re: libgdx - TileMap-rendering- Huge performance problems
|
on: 2013-01-23 00:16:41
|
|
I am using a mesh with indices + atlas, don't bind every single texture, for creating the atlas, I use the pixmappacker. -> render 400 tiles with 56 fps, 25.000 at 12 fps, it's worth using it. If you are using a mesh, you have to think of the length of the short[] of the indices -> create chunks. My tilemap (psydo-code): world.class Chunk[][] tileMap;
Chunk.cass int[][] chunkMap;
the spritebatcher isn't that bad, but normally I prefere geometry mesh.
best regards
|
|
|
|
|
4
|
Java Game APIs & Engines / OpenGL Development / Re: (OpenGL or own)Matrix functions, Render a Mesh many times (Geometry Instancing?)
|
on: 2013-01-23 00:09:06
|
1. After I did every tut I could find, I just started programming on my own. One huge and well written blog: http://fgiesen.wordpress.com/2011/07/01/a-trip-through-the-graphics-pipeline-2011-part-1/ 3.I don't know if it's the most effective way, but for rendering my tilemap, I collect all the vertices and texture-coords (from the texture-atlas, think of caching it, because the find("name") is quite slow) in a huge float[], in addition I add the indices. I think, that Triangles are rendered much faster. You should call the draw() and bind() method as little as possible. One problem about "geometric-mesh-rendering" is, that you have to thing of the size of the indices-array, it's a short[]. Therefore I create for each chunk a own mesh and render it. I pass 18 mb per second, but that's no problem, if you think for example about smartphones, the cpu + gpu are on the same chip -> you don't really have to care about it bottleneck. One great lib is libgdx, it has a lot of great features and offers you full opengl-"action". best regards
|
|
|
|
|
7
|
Games Center / Showcase / Re: Jackal
|
on: 2013-01-08 21:51:30
|
|
yes but that doesn't work during the boss-wave, you can't drive on the bottom because the enemies sometimes leave your screen on the bottom -> get shot. In addition I died because a random tank spawn out of my viewport and moved up into my field of view -> collision.
maybe you could add a "attach machine-gun to velocity-direction button" best regards
|
|
|
|
|
9
|
Games Center / Showcase / Re: Jackal
|
on: 2013-01-08 21:29:12
|
|
I like it, but I don't get how to control the "normal" shot, sometimes it works shooting in another direction but most of the time it just shoot north.
|
|
|
|
|
15
|
Java Game APIs & Engines / OpenGL Development / [Solved]libdgx - Mesh -> Matrix math curious result
|
on: 2013-01-04 01:18:21
|
Hi, after I am now able to create fragshaders, they don't even look that bad, thx for help   But now I have been wondering about the vertexshader for about 13 hours  I just don't get why vec4(aVertex,0,1)* uModelMatrix != vec4(aVertex,0,1) In my opinion uModelMatrix is an identity matrix so it should work. I expected a red field, the mesh coords are set weird because I just would like to see a red pixel. What I get: Nothing, absolutely nothing is rendered  There's the code, you could compile and test it yourself if you want  + downloadlink if you don't wanna grab the libs yourself: http://www.file-upload.net/download-7008284/ErrorShader.rar.html1 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
| import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Mesh; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.VertexAttribute; import com.badlogic.gdx.graphics.VertexAttributes.Usage; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.math.Matrix4;
public class ErrorShader implements ApplicationListener { MeshHelper meshHelper;
public static void main(String[] args) { LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); cfg.title = "Error"; cfg.useGL20 = true; cfg.width = 500; cfg.height = 500; cfg.resizable = false; new LwjglApplication(new ErrorShader(), cfg); } @Override public void create() { meshHelper = new MeshHelper(); meshHelper.createMesh(new float[] { -100.0f, -100.0f, 230.0f, 100.0f, 100f, 156.0f }); }
@Override public void resize(int width, int height) { }
@Override public void render() { Gdx.graphics.getGL20().glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.graphics.getGL20().glClear(GL10.GL_COLOR_BUFFER_BIT); Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND); meshHelper.drawMesh(); }
@Override public void pause() { }
@Override public void resume() { }
@Override public void dispose() { meshHelper.dispose(); } }
class MeshHelper { private Mesh mesh; private ShaderProgram redShader; private OrthographicCamera cam; private Matrix4 modelMatrix;
public MeshHelper() { createShader(); modelMatrix = new Matrix4(); cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); for(int i =0; i< modelMatrix.getValues().length; i++){ System.out.println("values "+ i+": " + modelMatrix.getValues()[i]); } }
public void createMesh(float[] vertices) { mesh = new Mesh(true, vertices.length, 0, new VertexAttribute(Usage.Position, 2, "aVertex")); mesh.setVertices(vertices); }
public void drawMesh() { if (mesh == null) throw new IllegalStateException("drawMesh called before a mesh has been created."); redShader.begin(); redShader.setUniformMatrix("uModelMatrix", modelMatrix); mesh.render(redShader, GL20.GL_TRIANGLES); redShader.end(); }
private void createShader() { String vertexShader = "attribute vec2 aVertex; \n" + "uniform mat4 uViewProjMatrix; \n" + "uniform mat4 uModelMatrix; \n" + "void main() \n" + "{ \n" + " gl_Position = vec4(aVertex,0,1)* uModelMatrix; \n" + "} \n"; String fragmentREDShader = "#ifdef GL_ES\n" + "#define LOWP lowp\n" + "precision mediump float;\n" + "#else\n" + "#define LOWP \n" + "#endif\n" + "\n" + "void main() {\n" + " gl_FragColor = vec4(1.0,0.0,0.0, 1.0);\n" + "}"; redShader = new ShaderProgram(vertexShader, fragmentREDShader); if (redShader.isCompiled() == false) throw new IllegalStateException(redShader.getLog()); } public void dispose() { mesh.dispose(); redShader.dispose(); } } |
thx for help, best regards
|
|
|
|
|
17
|
Java Game APIs & Engines / OpenGL Development / libdgx - Mesh Shader Blending Errors
|
on: 2013-01-02 23:37:06
|
Hi, I just don't get why the blue triangle is rendered, I think that Blend isn't enabled but I don't know what I could do to fix it. You can just compile and test it on your own if you want to, the code is "working", the shaders not  What I got:  -a blue triangle What I expected: -a red triangle, because the opacity from the blue one is 0 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
| import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Mesh; import com.badlogic.gdx.graphics.VertexAttribute; import com.badlogic.gdx.graphics.VertexAttributes.Usage; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
public class ErrorShader implements ApplicationListener { MeshHelper meshHelper;
public static void main(String[] args) { LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); cfg.title = "Error"; cfg.useGL20 = true; cfg.width = 500; cfg.height = 500; cfg.resizable = false; new LwjglApplication(new ErrorShader(), cfg); } @Override public void create() { meshHelper = new MeshHelper(); meshHelper.createMesh(new float[] { -1.0f, -1.0f, Color.toFloatBits(0, 0, 255, 0), 0.0f, 1f, Color.toFloatBits(0, 0, 255, 0), 1f, -1.0f, Color.toFloatBits(0, 0, 255, 0) }); }
@Override public void resize(int width, int height) { }
@Override public void render() { Gdx.graphics.getGL20().glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.graphics.getGL20().glClear(GL10.GL_COLOR_BUFFER_BIT); Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL10.GL_ONE_MINUS_SRC_ALPHA, GL10.GL_SRC_ALPHA); meshHelper.drawMesh(); }
@Override public void pause() { }
@Override public void resume() { }
@Override public void dispose() { meshHelper.dispose(); } }
class MeshHelper { private Mesh mesh; private ShaderProgram redShader; private ShaderProgram blueShader;
public MeshHelper() { createShader(); }
public void createMesh(float[] vertices) { mesh = new Mesh(true, vertices.length, 0, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(Usage.ColorPacked, 4, "a_color")); mesh.setVertices(vertices); }
public void drawMesh() { if (mesh == null) throw new IllegalStateException("drawMesh called before a mesh has been created."); redShader.begin(); mesh.render(redShader, GL20.GL_TRIANGLES); redShader.end(); blueShader.begin(); mesh.render(blueShader, GL20.GL_TRIANGLES); blueShader.end(); }
private void createShader() { String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color; \n" + "varying vec4 v_color; \n" + "void main() \n" + "{ \n" + " v_color = a_color; \n" + " gl_Position = a_position; \n" + "} \n";
String fragmentBLUEShader = "#ifdef GL_ES\n" + "#define LOWP lowp\n" + "precision mediump float;\n" + "#else\n" + "#define LOWP \n" + "#endif\n" + "\n" + "void main() {\n" + " gl_FragColor = vec4(0.0,0.0,1.0, 0.0);\n" + "}"; blueShader = new ShaderProgram(vertexShader, fragmentBLUEShader); if (blueShader.isCompiled() == false) throw new IllegalStateException(blueShader.getLog()); String fragmentREDShader = "#ifdef GL_ES\n" + "#define LOWP lowp\n" + "precision mediump float;\n" + "#else\n" + "#define LOWP \n" + "#endif\n" + "\n" + "void main() {\n" + " gl_FragColor = vec4(1,0,0,1);\n" + "}"; redShader = new ShaderProgram(vertexShader, fragmentREDShader); if (redShader.isCompiled() == false) throw new IllegalStateException(redShader.getLog()); } public void dispose() { mesh.dispose(); blueShader.dispose(); redShader.dispose(); }
} |
edit: Got it, if I use 1
| Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); |
it works, but I don't understand why the other one doesn't work. It would be great if someone could explain itThe text is german but the pictures are nice: http://wiki.delphigl.com/index.php/glBlendFunc#Beispielethx for help, best regards
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / Re: Specify What To Paint On? (Java2D)
|
on: 2013-01-02 11:25:00
|
Sry for code-block  How I did it, I hope I haven't earsed to much of my code, if you have questions left, feel free to ask. Main: 1 2 3 4 5 6 7 8 9 10 11 12
| public class Main { public static String version = "V 0.1 - Alpha"; public static int width = 1280; public static int height = 720; public static GameWindow gameWindow; public static boolean paused; public static void main(String[] args) throws IOException{ gameWindow = new GameWindow("Game " + version, width, height); } } |
JFrame: 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
| public class GameWindow extends JFrame { private static final long serialVersionUID = 1308619767172296296L; private Dimension dim; private GamePanel gpanel; public static GameWindow gw; public GameWindow(String title, int width, int height) throws IOException { super(title); gw = this; dim = new Dimension(width, height); setMaximumSize(dim); setMinimumSize(dim); setPreferredSize(dim); gpanel = new GamePanel(); add(gpanel); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); setUndecorated(true); setVisible(true); } |
JPanel attached on the Jframe 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public class GamePanel extends JPanel{ public GamePanel() throws IOException { super(); this.setLayout(null); KeyOptionsPanel.loadKeys();
moveThread = new MoveThread(this); start = new Thread(moveThread); start.start(); } public void paint (Graphics g) { Render.map(g); } } |
Gameloop: 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
| public class MoveThread implements Runnable{ private JComponent comp; private long duration, last = System.currentTimeMillis() - 20; public MoveThread(JComponent comp) { this.comp = comp; } @Override public void run() { while (Main.running) { duration = System.currentTimeMillis() - last; last = System.currentTimeMillis(); if (!Main.paused) CalculateMov.cm.run(duration); comp.repaint(); try { Thread.sleep(20); } catch (InterruptedException e) { } } } } |
I wouldn't use that gameloop anymore, that was my first one  I would recomment that one: http://www.java-gaming.org/topics/game-loops/24220/viewIf you use java2d, use the "double-buffered-renderer" You don't have to render Tiles, that aren't shown. It's a little bit tricky but to save performance, you can create an "startTileX", "startTileY" and "stopTileX", "stopTileY". You get the startTile[x/y] if you devide the cameraMovement by the size of one tile -> stopTile[x/y] = startTile[x/y] +[width/height] devided by size of one tile. The "/" isn't an mathematical sign, I am just to lazy to write it for x and y  best regards
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / Re: Specify What To Paint On? (Java2D)
|
on: 2013-01-02 10:53:32
|
I also have an [map].draw function but I did it like this: Why does your gamepanel extend Jpanel? pseudo-code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| GamePanel.class: private Map map; [...] public void paint (Graphics g) { Render.map(map,g); }
Map.class private JComponent comp; public Map(JComponent comp) { [...] this.comp = comp; }
render(){ [Here you could check if Jcomp has focus etc] [set the map in the GamePanel.class (if you need to)] comp.repaint(); } |
I don't like that pseudo that much, but it works. It should also be possible to use: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| GamePanel.class public Graphics paint (Graphics g) { return g; }
Map.class private JComponent comp; public Map(JComponent comp) { [...] this.comp = comp; }
render(){ Graphics g = comp.repaint(); [draw with g] } |
Edit: Are you sure, that you don't want to use more .class files? best regards
|
|
|
|
|
21
|
Discussions / General Discussions / Re: why are people trying to use Java2D to make games?
|
on: 2013-01-01 13:01:02
|
Please use a proper 'you' instead of 'u', it's burning my eyes out right now. Take a look at TheCodingUniverse for some LWJGL tutorials.
The "you" is one of my new Year's pledges. I already watched most of the youtubetutorials, I think they are quite good explained. -> Back to Topic, In my opinion awt offers a lot of great stuff for java2d, especially because you can write your own components, it's highly customizable. Furthermore if you use the "double-buffered-layer-renderer" and active rendering it's fast and accurate enough for desktop-applications. If you just want to add a scroll-pane in jogl/lwjgl/libgdx it's not that easy as it would be in java2d. best regards
|
|
|
|
|
22
|
Game Development / Newbie & Debugging Questions / timer vs polling vs thread.sleep
|
on: 2012-12-31 18:42:26
|
Hi, I got another question  I got a lot of sparetime at the moment  I've got some objects, after some time I have to execute a function (for example object.setAwake()). Would you use 1.timer 2. new thread + thread.sleep (I already read that I shouldn't use that) 3. a list with all objects and poll them I don't need a break condition like it's already implemented in the timer. best regards
|
|
|
|
|
23
|
Game Development / Newbie & Debugging Questions / Re: libdgx - Shaperenderer - Opacity
|
on: 2012-12-31 18:27:44
|
thx for explanation  The shaperenderer is just for prealpha-test-debugging-version. In the future I am not sure if I will use spritebatches or shaders. Spritebatches are very easy to use  I already did that tut, but I think I have to read more about shaders if I want to use them  Especially because from es 1.0 to 2.0 are some creepy changes and at the moment I often confuse the functions and wonder about the result  I just started learning opengl and maybe I did to big steps so I might haven't understood everything I thought I understood  best regards
|
|
|
|
|
24
|
Game Development / Newbie & Debugging Questions / Re: libdgx - Shaperenderer - Opacity
|
on: 2012-12-31 10:21:53
|
1 2 3 4
| Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND); Gdx.graphics.getGL10().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); |
I don't think that I am drawing sth at the moment or do I missunderstand it? best regards edit: Got it, although shaderrenderer uses gl10 I have to modify gl20  Does someone know why?
|
|
|
|
|
26
|
Game Development / Newbie & Debugging Questions / libdgx - Shaperenderer - Opacity
|
on: 2012-12-31 09:31:53
|
Hi, I am wondering about the Shaperenderer: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html1 2 3 4 5 6
| shapeRenderer.begin(ShapeType.FilledCircle); shapeRenderer.setColor(0, 0, 0.4f, 0.3f); shapeRenderer.filledCircle(100,100,20); shapeRenderer.setColor(1, 1, 0, 0.3f); shapeRenderer.filledCircle(100,100,10); shapeRenderer.end(); |
Normally I would use the spritebatch for drawing, but this time I just want to draw a circle that contains another circle with a different color. In addition the one on the bottom shouldshow through the other. I just don't get it who to enable the alpha-"function" / if you google it, it always shows articles about the spritebatcher. I thought 1 2
| Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND); Gdx.graphics.getGL10().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); |
would manage it, but "glEnable(GL10.GL_BLEND)" throws nullpointer.. I am new to opengl-fun and that's absolutely confusing me, I just don't get what I am doing wrong  thx for help and patience 
|
|
|
|
|
27
|
Game Development / Newbie & Debugging Questions / Re: which is faster?
|
on: 2012-12-31 09:13:29
|
|
How many sprites do you have? I don't think, that you will recognise any "speedboost", for example there's no difference in the "running-time of one loop" of my game if I just have to check 1 or 500 collisions. It might be worth it, if you got huge polygons and therefore a lot of verticles to check. What you could do is creating a circle around each sprite and check before if they collide (circle vs circle collision is faster then rect vs rect), but I in my opinion that's not worth it, too. best regards
|
|
|
|
|
28
|
Game Development / Newbie & Debugging Questions / Re: Random - Probability
|
on: 2012-12-31 07:47:28
|
@Master thx, it was to late, my brain was already in bed  @ctomni231 Let me try to explain it with an example: result should be between 10 and 100 if value is 0.01; the result probably is rather 10, 11, 12 (little results) if value is 0.25; the result probably is rather 25, 26, 27 (bigger little results) if value is 0.5; the result probably is rather 49, 50, 51 (medium results) if value is 0.75; the result probably is rather 74, 75, 76 (bigger medium results) if value is 0.99; the result probably is rather 98, 99, 100 (big results) I would like to set the expectancy of the result with "value" Hope it's now intelligible best regards
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Random - Probability
|
on: 2012-12-31 00:47:15
|
Hi, I am think about the probability of a number in a restricted area. psydo-code: 1 2 3 4 5
| float result float value int x = rand.nextInt(maxX - minX + 1) + minX; |
I thought about multiplying it with another random but I don't know how I put the "value" in it, because I would like to have a linear change of the highest probability. thx for help, <edit name = "Wasn't able to explain it, so here we go with an example"> Let me try to explain it with an example: result should be between 10 and 100 if value is 0.01; the result probably is rather 10, 11, 12 (little results) if value is 0.25; the result probably is rather 25, 26, 27 (bigger little results) if value is 0.5; the result probably is rather 49, 50, 51 (medium results) if value is 0.75; the result probably is rather 74, 75, 76 (bigger medium results) if value is 0.99; the result probably is rather 98, 99, 100 (big results) I would like to set the expectancy of the result with "value" </edit> best regards
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|