Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  Games Center / Cube World Projects / Starting A Voxel Game on: 2013-08-16 00:17:42
I have started making a Voxel game, so far I only have a block renderer with Textures. I can't find a tutorial that shows how to create a Chunk system that is easy to understand, so I can get it working with my code.

Block 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  
package test.voxel;

import java.io.IOException;

import org.lwjgl.opengl.GL11;

import test.voxel.Blocks.BlockType;
import test.voxel.data.TextureMananger;

public class BlockCreator {
   public static void NewBlock(float base,float x, float y, float z, BlockType blocktype) throws IOException {
     
     
      GL11.glBindTexture(GL11.GL_TEXTURE_2D,TextureMananger.getTexture(blocktype.GetTexture()));
      GL11.glTranslatef(x, y, z);

      GL11.glBegin(GL11.GL_QUADS);  
     
      // Back Face
     GL11.glTexCoord2f(1.0F,1.0F);
      GL11.glVertex3f(base, base, base);
      GL11.glTexCoord2f(0.0F,1.0F);
      GL11.glVertex3f(-base, base, base);
      GL11.glTexCoord2f(0.0F,0.0F);
      GL11.glVertex3f(-base, -base, base);
      GL11.glTexCoord2f(1.0F,0.0F);
      GL11.glVertex3f(base, -base, base);

      // Front Face
     GL11.glTexCoord2f(1.0F,1.0F);
      GL11.glVertex3f(base, base, -base);
      GL11.glTexCoord2f(0.0F,1.0F);
      GL11.glVertex3f(-base, base, -base);
      GL11.glTexCoord2f(0.0F,0.0F);
      GL11.glVertex3f(-base, -base, -base);
      GL11.glTexCoord2f(1.0F,0.0F);
      GL11.glVertex3f(base, -base, -base);

      // Right Face
     GL11.glTexCoord2f(1.0F,1.0F);
      GL11.glVertex3f(base, base, base);
      GL11.glTexCoord2f(0.0F,1.0F);
      GL11.glVertex3f(base, -base, base);
      GL11.glTexCoord2f(0.0F,0.0F);
      GL11.glVertex3f(base, -base, -base);
      GL11.glTexCoord2f(1.0F,0.0F);
      GL11.glVertex3f(base, base, -base);

      // Left Face
     GL11.glTexCoord2f(1.0F,1.0F);
      GL11.glVertex3f(-base, base, base);
      GL11.glTexCoord2f(0.0F,1.0F);
      GL11.glVertex3f(-base, -base, base);
      GL11.glTexCoord2f(0.0F,0.0F);
      GL11.glVertex3f(-base, -base, -base);
      GL11.glTexCoord2f(1.0F,0.0F);
      GL11.glVertex3f(-base, base, -base);

      // Top Face
     GL11.glTexCoord2f(1.0F,1.0F);
      GL11.glVertex3f(base, base, base);
      GL11.glTexCoord2f(0.0F,1.0F);
      GL11.glVertex3f(-base, base, base);
      GL11.glTexCoord2f(0.0F,0.0F);
      GL11.glVertex3f(-base, base, -base);
      GL11.glTexCoord2f(1.0F,0.0F);
      GL11.glVertex3f(base, base, -base);

      // Bottom Face
     GL11.glTexCoord2f(1.0F,1.0F);
      GL11.glVertex3f(base, -base, base);
      GL11.glTexCoord2f(0.0F,1.0F);
      GL11.glVertex3f(-base, -base, base);
      GL11.glTexCoord2f(0.0F,0.0F);
      GL11.glVertex3f(-base, -base, -base);
      GL11.glTexCoord2f(1.0F,0.0F);
      GL11.glVertex3f(base, -base, -base);
     
      GL11.glEnd();
   }
   
}



This is the out come of the game:


Thanks
2  Game Development / Newbie & Debugging Questions / Re: Illegal Argument Exception on: 2013-08-13 01:55:49
I think I found something:

Change
1  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

to
1  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);


(Make sure to include
GL11.
. I use static imports)


Changing the both of the GL_RGBA to  GL_RGBA8 worked. Thanks
3  Game Development / Newbie & Debugging Questions / Re: Illegal Argument Exception on: 2013-08-10 21:08:20
It points me to this line:
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data);

and,

data.flip(), data.rewind, and data.clear() all make it say 768
4  Game Development / Newbie & Debugging Questions / [Solved]Illegal Argument Exception on: 2013-08-10 20:57:37
I'm working on a 3d game and I've been having some trouble with my Texture Manager.
Here is the code I'm using (Sorry its a bit sloppy):
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  
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.IOException;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.HashMap;

import javax.imageio.ImageIO;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;




public class TextureMananger {
   public static final boolean DBG = true; //Debug
  public static TextureMananger img;
   public static ResourceLoader resourceLoader = new ResourceLoader();
   /* Number Of Textures Loaded */
   public static int totalImagesLoaded = 0;
   private static HashMap<String, Number> loadedImages = new HashMap<String, Number>();
   
   public static int loadTexture(String texture) throws IOException {
      if (loadedImages.get(texture) != null) {
         if (DBG) System.out.println("[Textures] Texture '" + texture.toString() + "' was already loaded! ID is " + loadedImages.get(texture.toString()).intValue() + ".");

         return loadedImages.get(texture.toString()).intValue();

      } else {
         BufferedImage image = ImageIO.read(resourceLoader.loadResource(texture));
         int width = image.getWidth();
         int height = image.getHeight();
         DataBufferByte rawData =  (DataBufferByte) image.getData().getDataBuffer();
         
         ByteBuffer data = BufferUtils.createByteBuffer(rawData.getSize());
           data.put(rawData.getData());
           data.rewind();
           //data.clear();
          IntBuffer scratch = BufferUtils.createIntBuffer(1);
           
           GL11.glGenTextures(scratch);
           GL11.glBindTexture(GL11.GL_TEXTURE_2D, scratch.get(0));
           GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
           GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
           GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data);
           GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
           totalImagesLoaded++;
           loadedImages.put(texture.toString(), scratch.get(0));
           System.out.println(TextureMananger.class.getClass().getResource(texture));
         if (DBG) System.out.println("[Textures] Texture '" + texture.toString() + "' was Loaded! ID is " + loadedImages.get(texture.toString()).intValue() + ".");
           return scratch.get(0);  
           
      }
     
   }

     
   
     
   
   
}


And here is the error im getting:

java.lang.IllegalArgumentException: Number of remaining buffer elements is 768, must be at least 1024. Because at most 1024 elements can be returned, a buffer with at least 1024 elements is required, regardless of actual returned element count


I'm not to good with buffers and rendering stuff, so any help would be appreciated.
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!