Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  Nothing is rendering  (Read 1125 times)
0 Members and 1 Guest are viewing this topic.
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Posted 2013-03-02 22:36:52 »

I recently re coded my chunk class because it badly needed it. I only got through the basics of the class before realizing it wasn't rendering anything! I make a new VBO, store 16^3 cubes in it, then translate the VBO to its render position. Here's the chunk 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  
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  
package com.mime.skyfox.Level;

import static org.lwjgl.opengl.GL11.GL_COLOR_ARRAY;
import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_VERTEX_ARRAY;
import static org.lwjgl.opengl.GL11.glColorPointer;
import static org.lwjgl.opengl.GL11.glDisableClientState;
import static org.lwjgl.opengl.GL11.glDrawArrays;
import static org.lwjgl.opengl.GL11.glEnableClientState;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glTranslatef;
import static org.lwjgl.opengl.GL11.glVertexPointer;
import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.glBindBuffer;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL15;

import com.mime.skyfox.Blocks.Block;

public class BaseChunk {

   // x - left/right y - up/down y - forward/backward

   public static final int CHUNK_X = 16;
   public static final int CHUNK_Y = 16;
   public static final int CHUNK_Z = 16;

   public boolean rebuild = false;

   FloatBuffer blockPositionData;
   FloatBuffer vertexColorData;

   private Block[][][] blocks;
   private int vboBlockData;
   private int vboColorData;

   private int chunkStartX;
   private int chunkStartY;
   private int chunkStartZ;

   public BaseChunk(int x, int z, int y) {
      chunkStartX = x;
      chunkStartY = y;
      chunkStartZ = z;

      blocks = new Block[CHUNK_X][CHUNK_Z][CHUNK_Y];

      for (int xx = 0; xx < CHUNK_X; xx++) {
         for (int zz = 0; zz < CHUNK_Z; zz++) {
            for (int yy = 0; yy < CHUNK_Y; yy++) {
               blocks[xx][zz][yy] = Block.Grass;
            }
         }
      }
   }

   public void rebuildChunk() {
      vboBlockData = GL15.glGenBuffers();
      blockPositionData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

      vboColorData = GL15.glGenBuffers();
      vertexColorData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

      for (int xx = 0; xx < CHUNK_X; xx++) {
         for (int zz = 0; zz < CHUNK_Z; zz++) {
            for (int yy = 0; yy < CHUNK_Y; yy++) {
               blockPositionData.put(makeCube((float) chunkStartX + xx, (float) chunkStartZ + zz, chunkStartY + yy));
               vertexColorData.put(getColor(Block.Grass));
            }
         }
      }
      vertexColorData.flip();
      blockPositionData.flip();
   }

   private float[] makeCube(float x, float z, float y) {
      int offset = Block.size / 2;

      return new float[] { x + offset, y + offset, z, x - offset, y + offset, z, x - offset, y + offset, z - Block.size, x + offset, y + offset, z - Block.size, x + offset, y - offset, z - Block.size, x - offset, y - offset, z - Block.size, x - offset, y - offset, z, x + offset, y - offset, z, x + offset, y + offset, z - Block.size, x - offset, y + offset, z - Block.size, x - offset, y - offset, z - Block.size, x + offset, y - offset, z - Block.size, x + offset, y - offset, z, x - offset, y - offset, z, x - offset, y + offset, z, x + offset, y + offset, z, x - offset, y + offset, z - Block.size, x - offset, y + offset, z, x - offset, y - offset, z, x - offset, y - offset, z - Block.size, x + offset, y + offset, z, x + offset, y + offset, z - Block.size, x + offset, y - offset,
            z - Block.size, x + offset, y - offset, z };
   }

   private int getColor(Block block) {
      return block.color;
   }

   public void render(int x, int z, int y) {
      glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
      glVertexPointer(3, GL_FLOAT, 0, 0L);

      glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
      glColorPointer(3, GL_FLOAT, 0, 0L);

      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);
      for (int yy = 0; yy < y; yy++) {
         for (int xx = 0; xx < x; xx++) {
            for (int zz = 0; zz < z; zz++) {
               glPushMatrix();
               glTranslatef(xx, zz, yy);
               glDrawArrays(GL_QUADS, 0, 24);
               glPopMatrix();
            }
         }

      }
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
   }
}


And I call it like this:
1  
2  
3  
baseChunk = new BaseChunk(16, 16, 16);
      baseChunk.rebuildChunk();
      baseChunk.render(16, 16, 16);

Could it have something to do with my offsets in the make cube method?

Offline Axeman

Senior Member


Medals: 7



« Reply #1 - Posted 2013-03-03 17:47:53 »

Correct me if I´m wrong, but I can´t see that you´re binding "vboBlockData" to "blockPositionData".

Try to add

1  
2  
3  
4  
5  
6  
7  
glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
glBufferData(GL_ARRAY_BUFFER, blockPositionData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
glBufferData(GL_ARRAY_BUFFER, vertexColorData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);


in your rebuildChunk()

On a side note to anyone who might know: Do you need to "unbind" with "glBindBuffer(GL_ARRAY_BUFFER, 0)" or does it suffice to just bind another buffer..?

Offline theagentd
« Reply #2 - Posted 2013-03-03 18:11:47 »

On a side note to anyone who might know: Do you need to "unbind" with "glBindBuffer(GL_ARRAY_BUFFER, 0)" or does it suffice to just bind another buffer..?
You can just directly bind another buffer.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Axeman

Senior Member


Medals: 7



« Reply #3 - Posted 2013-03-03 18:21:32 »

I thought so but it´s always good to know. Smiley Thanks, AgentD!
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #4 - Posted 2013-03-06 23:10:35 »

Well I tried to do that and for some reason its just not working :/ Its getting very frustrating now...
Here's my current code:
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  
package com.mime.skyfox.Level;

import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
import static org.lwjgl.opengl.GL11.GL_COLOR_ARRAY;
import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_VERTEX_ARRAY;
import static org.lwjgl.opengl.GL11.glColorPointer;
import static org.lwjgl.opengl.GL11.glDisableClientState;
import static org.lwjgl.opengl.GL11.glDrawArrays;
import static org.lwjgl.opengl.GL11.glEnableClientState;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glTranslatef;
import static org.lwjgl.opengl.GL11.glVertexPointer;
import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.glBindBuffer;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL15;

import com.mime.skyfox.Blocks.Block;

public class BaseChunk {

      // x - left/right y - up/down y - forward/backward

      public static final int CHUNK_X = 16;
      public static final int CHUNK_Y = 16;
      public static final int CHUNK_Z = 16;

      public boolean rebuild = false;

      FloatBuffer blockPositionData;
      FloatBuffer vertexColorData;

      private Block[][][] blocks;
      private int vboBlockData;
      private int vboColorData;

      private int chunkStartX;
      private int chunkStartY;
      private int chunkStartZ;

      public BaseChunk(int x, int z, int y) {
         chunkStartX = x;
         chunkStartY = y;
         chunkStartZ = z;

         blocks = new Block[CHUNK_X][CHUNK_Z][CHUNK_Y];

         for (int xx = 0; xx < CHUNK_X; xx++) {
            for (int zz = 0; zz < CHUNK_Z; zz++) {
               for (int yy = 0; yy < CHUNK_Y; yy++) {
                  blocks[xx][zz][yy] = Block.Grass;
               }
            }
         }
      }

      public void rebuildChunk() {
         vboBlockData = GL15.glGenBuffers();
         blockPositionData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

         vboColorData = GL15.glGenBuffers();
         vertexColorData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

         for (int xx = 0; xx < CHUNK_X; xx++) {
            for (int zz = 0; zz < CHUNK_Z; zz++) {
               for (int yy = 0; yy < CHUNK_Y; yy++) {
                  blockPositionData.put(makeCube((float) chunkStartX + xx, (float) chunkStartZ + zz, chunkStartY + yy));
                  vertexColorData.put(getColor(Block.Grass));
               }
            }
         }
         glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
         GL15.glBufferData(GL_ARRAY_BUFFER, blockPositionData, GL_STATIC_DRAW);
         glBindBuffer(GL_ARRAY_BUFFER, 0);

         glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
         GL15.glBufferData(GL_ARRAY_BUFFER, vertexColorData, GL_STATIC_DRAW);
         glBindBuffer(GL_ARRAY_BUFFER, 0);

         vertexColorData.flip();
         blockPositionData.flip();
      }

      private float[] makeCube(float x, float z, float y) {
         int offset = Block.size / 2;

         return new float[] { x + offset, y + offset, z, x - offset, y + offset, z, x - offset, y + offset, z - Block.size, x + offset, y + offset, z - Block.size, x + offset, y - offset, z - Block.size, x - offset, y - offset, z - Block.size, x - offset, y - offset, z, x + offset, y - offset, z, x + offset, y + offset, z - Block.size, x - offset, y + offset, z - Block.size, x - offset, y - offset, z - Block.size, x + offset, y - offset, z - Block.size, x + offset, y - offset, z, x - offset, y - offset, z, x - offset, y + offset, z, x + offset, y + offset, z, x - offset, y + offset, z - Block.size, x - offset, y + offset, z, x - offset, y - offset, z, x - offset, y - offset, z - Block.size, x + offset, y + offset, z, x + offset, y + offset, z - Block.size, x + offset, y - offset,
               z - Block.size, x + offset, y - offset, z };
      }

      private int getColor(Block block) {
         return block.color;
      }

      public void render(int x, int z, int y) {
         glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
         glVertexPointer(3, GL_FLOAT, 0, 0L);

         glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
         glColorPointer(3, GL_FLOAT, 0, 0L);

         glEnableClientState(GL_VERTEX_ARRAY);
         glEnableClientState(GL_COLOR_ARRAY);
         for (int yy = 0; yy < y; yy++) {
            for (int xx = 0; xx < x; xx++) {
               for (int zz = 0; zz < z; zz++) {
                  glPushMatrix();
                  glTranslatef(xx, zz, yy);
                  glDrawArrays(GL_QUADS, 0, 24);
                  glPopMatrix();
               }
            }

         }
         glDisableClientState(GL_VERTEX_ARRAY);
         glDisableClientState(GL_COLOR_ARRAY);
      }
   }

I call a new instance of the chunk with the parameters 0, 0, 0 as the starting point for the chunk to generate. Then I call the rebuildChunk method, and then the render method with parameters of 16, 16, 16. Still just a blank screen.

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.

xsi3rr4x (53 views)
2014-04-15 18:08:23

BurntPizza (51 views)
2014-04-15 03:46:01

UprightPath (65 views)
2014-04-14 17:39:50

UprightPath (48 views)
2014-04-14 17:35:47

Porlus (65 views)
2014-04-14 15:48:38

tom_mai78101 (89 views)
2014-04-10 04:04:31

BurntPizza (149 views)
2014-04-08 23:06:04

tom_mai78101 (245 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!