Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  Java Game APIs & Engines / OpenGL Development / Re: interleaved VBO and textures (Problem) on: 2014-06-01 17:15:52
I feel so bad right now. I thought i could be this so i'd implemented a method to move the camera around ... But forget to disable face-culling. I am soooo sorry.

I already read some things about the left-handed and right-handed system and i should have figure this out. Anyway, thank you a lot for your help, if you want i'll keep you aware my progress on the game Wink

P.S: Of course it's working, i wouldn't say this if it wont ^^
2  Java Game APIs & Engines / OpenGL Development / Re: interleaved VBO and textures (Problem) on: 2014-06-01 00:33:37
Hello, to be honest i'm no sure of what to do with my texture buffer. I had commented out the GL_VERTEX_ARRAY because of a bug but i whase due to another problème. so i change  a little bit but still don't have any result. Maybe the triangle i drawn but the camera is not in front of it but i'm 90% sure it's not this.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
private void drawCube(){
      texture.bind();
      glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandleChunk);
      glEnableClientState(GL_VERTEX_ARRAY);
      glVertexPointer(3, GL_FLOAT, 5*4, 0L);
      glClientActiveTexture(GL_TEXTURE0);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
      glTexCoordPointer(2, GL_FLOAT, 5*4, 3*4 );
      glDrawArrays(GL_TRIANGLES, 0, 3);
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   }


P.S: Thank you for your help / time quew8, if i manage to make this work with your help, i'll name my firstborn after you Smiley
3  Java Game APIs & Engines / OpenGL Development / Re: interleaved VBO and textures (Problem) on: 2014-05-31 21:35:15
Ok, thanks for the advices. I'll start looking into it, but first i would like to make it work in order to continue on other features.

I Wrote a small thing that should draw a single triangle with an texture on it but all i have is an empty black window. Can anybody see what i am doing wrong and (maybe) if this is even worst than i did before ?

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  
public class Triangles {

   private Texture texture;
   private FloatBuffer textureData;
   private Vector3f position, rotation;
   private int vboVertexHandleChunk;
   private FloatBuffer interleavedBuffer;
   private int floatByteSize = 4;
   private int positionFloatCount = 3;
   private int floatsPerVertex = positionFloatCount*2;
   private int texId;

   public Triangles(){
      this.initDisplay();
      this.openGL();
      position = new Vector3f(0f, 0, 0);
      rotation = new Vector3f(0, 0, 0);
   }

   public static void main(String[] args) {
      Triangles test = new Triangles();
      test.openImage();

      test.renderLoop();

   }

   private void openGL(){
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(50, 800/600, 0.01f, 20);
      glMatrixMode(GL_MODELVIEW);  
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glLoadIdentity();

   }

   public void initDisplay(){
      try{
         Display.setResizable(true);
         Display.setDisplayMode(new DisplayMode((int)800, (int)600));
         Display.setTitle("Dino Survive");
         Display.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
         Display.destroy();
         System.exit(1);
      }

      Mouse.setGrabbed(false);
   }

   private void renderLoop(){
      genCubes();
     
      while(!Display.isCloseRequested()){
     
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
         glLoadIdentity();
         
         useView();
         input();
         drawCube();
         
         Display.sync(60);
         Display.update();
      }

      Display.destroy();
   }

   private void openImage(){
      try {
         texture = TextureLoader.getTexture("PNG",
               ResourceLoader.getResourceAsStream("../DinoSurvive/res/text.png"));
      } catch (IOException e) {
         e.printStackTrace();
      }

      textureData = BufferUtils.createFloatBuffer(3 * 2);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   }

   private void useView(){
      glRotatef(rotation.x, 1, 0, 0);
      glRotatef(rotation.y, 0, 1, 0);
      glRotatef(rotation.z, 0, 0, 1);
      glTranslatef(position.x, position.y, position.z);
      System.out.println(position);
   }
   
   private void genCubes(){
      vboVertexHandleChunk = GL15.glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandleChunk);
     
      interleavedBuffer = BufferUtils.createFloatBuffer(3*2+3*3);
      interleavedBuffer.put(new float[]{
            0, 0, 3, 0.03125f+0, 0.03125f+0,
            -1, 0, 3, 0.03125f+0, 0+0,
            -1, -1, 3, 0+0, 0.03125f+0});
      interleavedBuffer.flip();
     
      glBufferData(GL_ARRAY_BUFFER, interleavedBuffer, GL_STATIC_DRAW);
   }
   
   private void drawCube(){
     
      glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandleChunk);
      //glEnableClientState(GL_VERTEX_ARRAY);
     glVertexPointer(3, GL_FLOAT, 5*4, 0L);
      glClientActiveTexture(GL_TEXTURE0);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
      glTexCoordPointer(2, GL_FLOAT, 5*4, 3*4 );
      glDrawArrays(GL_TRIANGLES, 0, 6);
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   }

}


I remove some of the method to make the code a little less longer.
One again, thank you for reading and caring !
4  Java Game APIs & Engines / OpenGL Development / Re: interleaved VBO and textures (Problem) on: 2014-05-29 00:48:46
It is in fact little bit more clear for me. Don't worry about my old post it whase in the time i didn't understand very well those concepts.

But how did i "translate" to an other position in my texture vbo ?

For now all i have is a big png file with the different texture for the cube and i interleaved my big one O' chunk vbo like so : CCCTTCCCTTCCCTT where C is the cube coordinates and T the texture coordinate.

Thank you for your responses.
5  Java Game APIs & Engines / OpenGL Development / Re: interleaved VBO and textures (Problem) on: 2014-05-28 17:35:54
hi ! I understund what you meant but doing so the whole VBO (aka: the chunk) will have the same texture, what i want is i different texture information vor each cube separatly.
6  Java Game APIs & Engines / OpenGL Development / interleaved VBO and textures (Solved) on: 2014-05-28 17:10:38
Heeeelllo everyone ! I come to you a second time to talk you about how lost i am in lwjgl. The thing is that i try to implement a voxel base engine. To do so i create a lot of class and methodes that are working ... correctly but i ran into a major issue when starting to work with VBO. I've manage to make a "beautiful" and make it all working smooth but my framerate where to low because i where createing a VBO for each single cubes i've draw.

Here is a link of my previous post on the same project http://www.java-gaming.org/topics/huge-lag-in-voxel-engine-using-lwjgl/32692/view.html

So now i've understund that i needed to make just one VBO per chunk so the drawing part would be smoother. For what i've see i must use the interleaving technic to render all of this but it's not realy clear to me. I have a few questions about it :
*Do i need shader to manage to render my chunk while interleaving ?
*If yes or no ... how do i do.

At this point i'm so much lost if good samaritan could help me and answer my questions "i would be sooo happy".

Thank you i advance at least for reading this.
7  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-11 10:49:47
Hello,

so i try what you said to me, so i intervaled mes triangle like so : VVVTTVVVTTVVVTT ...
but nothing change. I'm sorry i do not test with only one but it would to longue to figure out to rearrange my code to make a single triangle.

Here what i did:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public void genCubes(TextureManager texMan){
      interleavedBuffer = BufferUtils.createFloatBuffer(renderCubes.size()*3*2*36);
      float[] textArray, cubeArray;
      int i;

      for(Cube3dVbo cube : renderCubes){
         textArray = texMan.genText(cube.getType(), cube.getTextX(), cube.getTextY());
         cubeArray = cube.genCubes();
         int j = 0;
         
         for(i =0; i<108; i+=3){
            interleavedBuffer.put(cubeArray[i]);
            interleavedBuffer.put(cubeArray[i+1]);
            interleavedBuffer.put(cubeArray[i+2]);
           
            interleavedBuffer.put(textArray[j]);
            interleavedBuffer.put(textArray[j+1]);
            System.out.println(i +" " + j);
            j+=2;
         }
   
      }
      interleavedBuffer.flip();
   }
8  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-10 15:21:56
Hi,

so 'positionFloatCount' is 3 which i change in 2 for the the call of glVertexAttribPointer. I also try several combination with the offset but i still have a clear screen with nothing drawn on it.
9  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-09 19:07:50
That a good advice but the thing is ... I don't understand all of what i am doing.

So yeah i really need help sorry. I just tryed random thinks based on what i could find on textured vbo and intervaling but it's not all clear to me.

I don't heaven see how am i drawing all the cube then the textured and not a triangle at a time.

Sorry and thanks for the answer.
10  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-09 17:24:16
@Mike : Yup i've already find this (really helpful) post but i must have messed up something by trying to reproduce it.

I'll put there my generating and rendering methods and if you want to watch the full project, chek the "problem" branch on the github link (https://github.com/Akinesis/DinoSurvive/tree/problem)

The chunk class (handling the vbo):
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  
//call befor the rendering loop
public void genVBO(){
      vboVertexHandleChunk = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexHandleChunk);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, interleavedBuffer, GL15.GL_STATIC_DRAW);

      // -- Now we can split our interleaved data over 2 attribute lists
     // First up is our positional information in list 0
     GL20.glVertexAttribPointer(0, positionFloatCount, GL11.GL_FLOAT, false,
            vertexFloatSizeInBytes, 0);

      // Second is our texture information in list 1, for this we also need the offset
     int byteOffset = floatByteSize * 2;
      GL20.glVertexAttribPointer(1, positionFloatCount, GL11.GL_FLOAT, false, vertexFloatSizeInBytes, byteOffset);

      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
      GL30.glBindVertexArray(0);

   }

//put each cube int the Buffer
//the two genCUbe method return an array of float (the coordinates of the cube and the texture's one)
public void genCubes(TextureManager texMan){
      interleavedBuffer = BufferUtils.createFloatBuffer(renderCubes.size()*3*2*36);
      for(Cube3dVbo cube : renderCubes){
         interleavedBuffer.put(cube.genCubes());
         interleavedBuffer.put(texMan.genText(cube.getType(), cube.getTextX(), cube.getTextY()));
      }
      interleavedBuffer.flip();
   }

//a monkey with a keyboard would have done something better than this.
//this is the method called in the rendering loop
public void draw(TextureManager texMan){
      //texMan.bindBuffer();
     GL13.glActiveTexture(GL13.GL_TEXTURE0);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, texMan.getTextVBO());
     
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexHandleChunk);
     
      glDrawArrays(GL_TRIANGLES, 0, 36*renderCubes.size());
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
   }


The textureManager 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  
//the constructor, also, i do not know what i am doing here, at least for half of the code
public TextureManager() {
      tWidth = 0;
      tHeight = 0;
      try {
         // Open the PNG file as an InputStream
        InputStream in = new FileInputStream("res/text.png");
         // Link the PNG decoder to this stream
        PNGDecoder decoder = new PNGDecoder(in);
         
         // Get the width and height of the texture
        tWidth = decoder.getWidth();
         tHeight = decoder.getHeight();
         // Decode the PNG file in a ByteBuffer
        buf = ByteBuffer.allocateDirect(
               4 * decoder.getWidth() * decoder.getHeight());
         decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
         buf.flip();
         in.close();
      } catch (IOException e) {
         e.printStackTrace();
         System.exit(-1);
      }

      textureData = BufferUtils.createFloatBuffer(36 * 2);
      //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     
      textVBO = GL11.glGenTextures();
      GL13.glActiveTexture(GL13.GL_TEXTURE0);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, textVBO);

      // All RGB bytes are aligned to each other and each component is 1 byte
     GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
     
      // Upload the texture data and generate mip maps (for scaling)
     GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0,
      GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
      GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

      // Setup the ST coordinate system
     GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
            GL11.GL_NEAREST);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
            GL11.GL_LINEAR_MIPMAP_LINEAR);
   }


Here, i think you got everything. If you not hate me after seeing what i'm doing here and still wanna help, thank you. Otherwise thank you for at least reading me.
11  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-08 16:21:22
Hi guys, first of all, thanks for your advices. With them i managed to do much better but i'm stuck again and maybe you could help (i could make a new post but the problem is related to the first one so ...).

Anyway ! I put all my cubes coordinate into one and only vbo (on the chunk) and to bind each cube with the specific location of the texture, i stored the coordinate into the same vbo (the same float buffer on the vbo). For as much as i understand, i must "intervaled" my vbo rendering passing in argument many things so i will work. But right know all i have i my display and nothing in it. My cube wont render anymore.

So if someone could try to explain me how all of this work (i can show you the function i'm using), it would be verry nice.

Thanks.
12  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-06 05:45:02
So if i want performance but being able to draw each cube with is specific texture i have to make a vbo per potential texture ?

That seems litle bit hardore does'nt it ? What if i have (i a bright future) 100+ type of cubes ? It's mean each chunk will have 100 different vbo ?

It will always be less than 4096 but ...
13  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-06 05:33:07
I'll looking for it, it seems interesting. But I already a-handle texturing with a unique png file. For now here what it's look like :



(i draw the texture myself so it's not very nice ...)

What i do when i draw is this :
-Put the coordinates of the cube in the vbo
-Take the coordinate of the associate texture in a second vbo
-draw the cube
-Back to step 1 with another cube.

But if i use a single vbo per chunk (aka a big array of float) how can i say which cube i want to draw (or i am drawing) at a particular moment to load the good coordinates ?
14  Game Development / Performance Tuning / Re: Huge lag in voxel engine using lwjgl on: 2014-04-06 05:11:32
I figured it was the solution but if i do so, i could i be able to map the associate texture to the cube. I still need to draw the texture (wich difere for a cube to an other) .

Or maybe ther's somthing i'ved miss about VBOs ?
15  Game Development / Performance Tuning / Huge lag in voxel engine using lwjgl on: 2014-04-06 00:47:26
everyone ! First of all, please excuse my english, i'm just a poor frenche programer who's fighting for a project maybe a little to big for him. Cheesy

So, let me explain : I start developing a voxel engine using lwjgl. To do so, i implemented several class such as chunk, chunkManger (which of course manage all the chunks in the game) and of course cubes. There's a lot more but this is the basics.

To draw my cubes i use VBO (Vertex buffer Object), the chunk have the main vbo an i update it for every cube i have to draw at each frame of the game. As you can think, it's result of massive lags for nothing more than 400 cubes to draw. I've of course enable face-culling and i have a function that make sure to render only the visible cubes.

So me question is if anybody have the patience and the kindness to look at my sources (https://github.com/Akinesis/DinoSurvive/) and tell me what i do wrong (though i already have an idea why).

Well thank you for reading me and maybe thank you for helping me.

P.S: I'm not sure to be in the right section so sorry if i'm not.
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.

ctomni231 (39 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47

Riven (37 views)
2014-07-14 11:51:35

quew8 (33 views)
2014-07-13 13:57:52

SHC (70 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!