Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Only one block in chunk being drawn when using textures  (Read 4240 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Member


Medals: 1



« Posted 2013-03-31 18:56:59 »

Hi,

Strange one this, when I draw all my blocks for a chunk, if using textures, only one block per chunk is drawn?

This is my render code for a block:

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  
private void renderBlock(Block.BlockType type) {
       GL11.glPushMatrix();
       GL11.glEnable(GL_TEXTURE_2D);
     
      // Get texture for what player is holding - we use the TextureManager singleton for this
     TextureBuffer texture = TextureManager.getInstance().getTexture(t);
      GL11.glBindTexture(GL_TEXTURE_2D, texture.textureId);

      GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
      GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
      GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
      GL11.glTexParameteri( GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST );  // GL_LINEAR
     GL11.glTexParameteri( GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST );  // GL_LINEAR
     
      // Make sure we are using our TextureBuffer object
     GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA,
            texture.decoder.getWidth(),
            texture.decoder.getHeight(),
            0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE,
            texture.buf);
     
      GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, 0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, 0.5f);   // Top Left Of The Texture and Quad
     // Back Face
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, -0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, -0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, -0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, -0.5f);   // Bottom Left Of The Texture and Quad
     // Top Face
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, -0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f(-0.5f, 0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f( 0.5f, 0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, -0.5f);   // Top Right Of The Texture and Quad
     // Bottom Face
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f(-0.5f, -0.5f, -0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f( 0.5f, -0.5f, -0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     // Right face
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, -0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, -0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, 0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     // Left Face
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, -0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, 0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, -0.5f);   // Top Left Of The Texture and Quad      
       GL11.glEnd();
        glColor3f(1,1,1);
        GL11.glPopMatrix();      
   }


Is it because I'm binding the same texture id for each block?

My 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  
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  
public class TextureManager {

   Map<BlockType,TextureBuffer> myTextures = new HashMap<BlockType, TextureBuffer>();

   // Add ALL texture types here - see Block.java
  private final static BlockType types[] =
                              { BlockType.BlockType_Grass,
                                BlockType.BlockType_Dirt,
                                BlockType.BlockType_Wood,
                              };
   
   private InputStream in;

   private static TextureManager instance = null;
   
   public synchronized static TextureManager getInstance()
   {
      if(instance == null)
      {
         instance = new TextureManager();
      }
      return instance;  
   }
   
   
   public TextureManager() {
   }

   public TextureBuffer getTexture(BlockType t)
   {
      TextureBuffer tb = (TextureBuffer)myTextures.get(t);
      return tb;
   }
   
   public boolean loadAllTextures() {
      boolean bAllLoaded = true;

      try
      {
         for (int i = 0; i < types.length; i++) {
            TextureBuffer tb = new TextureBuffer();
            if (!loadToolTexture(tb, types[i])) {
               System.out.println("Failed to load texture:" + types[i]);
               bAllLoaded = false;
               break;
            } else {
               myTextures.put(types[i],tb);
               System.out.println("Texture:"+types[i] + " added.");
            }
         }
      } catch(IOException io) {  System.out.println(io.getMessage()); bAllLoaded = false;}
      return bAllLoaded;
   }

   private boolean loadToolTexture(TextureBuffer tb, BlockType t) throws IOException{
      String texturePath = "";
      boolean bLoaded = true;
      try {
         switch (t) {
         case BlockType_Grass:
            texturePath = "grass16x16.png";
            break;
         case BlockType_Dirt:
            texturePath = "grassdirt.png";
            break;
         case BlockType_Wood:
            texturePath = "crate16x16.png";
            break;
         case BlockType_Stone:
            texturePath = "stone.png";
            break;
         case BlockType_Sand:
            texturePath = "sand.png";
            break;
         case BlockType_Water:
            texturePath = "water.png";
            break;
         case BlockType_Snow:
            texturePath = "snow.png";            
            break;
         default:
            texturePath = "grass16x16.png";
         }
         in = new FileInputStream("res/" + texturePath);
         tb.decoder = new PNGDecoder(in);

         tb.buf = ByteBuffer.allocateDirect(4 * tb.decoder.getWidth()
               * tb.decoder.getHeight());
         tb.decoder.decode(tb.buf, tb.decoder.getWidth() * 4, Format.RGBA);
         tb.buf.flip();
         tb.textureId = GL11.glGenTextures();
      } catch (Exception e) {
         System.out.println(e.getMessage());
         bLoaded = false;
      }
      finally {
         in.close();
      }
      return bLoaded;
   }


and TextureBuffer:

1  
2  
3  
4  
5  
6  
public class TextureBuffer {
   public BlockType t;
   public ByteBuffer buf;
   public int textureId;
   public PNGDecoder decoder;
}


All textures are loaded at the start of the world creation.  Only three textures at the moment, so just three texture id's.

I guess I'm doing something stupid?!

Any help is much appreciated and sorry if posted this in wrong section!

Steve
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #1 - Posted 2013-03-31 19:08:58 »

In line 6 you bind a texture:
1  
TextureBuffer texture = TextureManager.getInstance().getTexture(t);

But I don't know what t is and where it comes from. Maybe this is important.

Anyway, it seems you are binding a texture with every call of renderBlock. This means, every rendered block gets it's own call to bind(). This is a waste of ressources, because bind() is very expensive. When you have a TextureManager, you should use it to bind a texture when it is not currently bound. Like this:

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  
public class TextureManager {
   
   private static TextureManager reference;
   private HashMap<String,Image> dataBase;
   private int boundTexture;  //################ this one here ##############
  private static boolean debug;
   
   public TextureManager(){
      boundTexture = 0;
      dataBase = new HashMap<String,Image>();
   }
   
   public static TextureManager getTextureManager(){
      if(reference == null)
         reference = new TextureManager();
      return reference;
   }
   
   public void addTexture(String name, String path){
      if(dataBase.containsKey(name))
         System.err.println("Image with key " + name + " already in database!");
      else{
         Texture tex = loadTexture(path);
         dataBase.put(name, new Image(tex));
      }
   }
   
   public int getID(String name){
      return dataBase.get(name).getTextureID();
   }
   
   public void bind(String texName){
      bind(this.getID(texName));
   }

   public void bind(int texture){ // ############# and this method here ############
     if(texture != boundTexture){
         GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
         if(debug)
            System.out.println("Bind texture: " + texture);
      }
      else{
         if(debug)
            System.out.println("No bind necessary for: " + texture);
      }
      boundTexture = texture;
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
   }
        // ... and so on


This way you can bind whatever you want, it will only bind a new texture when needed.
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #2 - Posted 2013-03-31 19:17:16 »

By the way:
you are using
1  
2  
 GL11.glPushMatrix();
GL11.glPopMatrix();

in your code, but there is no transformation. At least I can't find one... Maybe this is a relict of previous versions of your code? But this can also be a source of problems, if your translation isn't done right at other places in your code.
Maybe all your blocks are rendered at the same position?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longor1996
« Reply #3 - Posted 2013-03-31 19:28:52 »

@steg90

How are you rendering a Chunk?
What's in the loop that draws the single blocks?

- Longor1996

PS: Im asking this because you are using my "off_vertex" method wrapper trick.

Sorry for my bad English! That's because i am from Germany.
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #4 - Posted 2013-03-31 19:30:56 »

Ah, thats why there is no translation, because of your trick? I forgot about that. Smiley
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 757
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2013-03-31 19:54:14 »

External code probably sets glBegin once, while for each block, you call glEnd. Therefore only the first block is rendered.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline steg90

Senior Member


Medals: 1



« Reply #6 - Posted 2013-03-31 20:05:34 »

Hi,

If I don't use textures I get all the cubes drawn.

Code which creates a chunk:

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  
private int createChunkList() {

      tx = 0; ty = 0; tz = 0;
      int iHidden = 0;
      int iBlockCount = 0;
      boolean bLeft = !false;
      boolean bRight = !false;
      boolean bAbove = !false;
      boolean bBelow = !false;
      boolean bFront = !false;
      boolean bBack = !false;

      boolean bDefault = true;
     
       glEnable(GL11.GL_CULL_FACE);
      glBegin(GL11.GL_QUADS);

      for (int x = 0; x < Chunk.CHUNK_SIZE; x++) {
         for (int y = 0; y < Chunk.CHUNK_SIZE; y++) {
            for (int z = 0; z < Chunk.CHUNK_SIZE; z++) {
               if(!GetBlock(x,y,z).IsActive())  //
              {
                  continue;
               }
               bLeft = bDefault;
               if(x > 0)
               {
                  bLeft = Blocks[x-1][y][z].IsActive();
               } else bLeft = false;
               bRight = bDefault;
               if(x < Chunk.CHUNK_SIZE - 1)
               {
                  bRight = Blocks[x+1][y][z].IsActive();
               } else bRight = false;
               bAbove = bDefault;
               if(y > 0)
               {
                  bAbove = Blocks[x][y-1][z].IsActive();
               } else bAbove = false;
               bBelow = bDefault;
               if(y < Chunk.CHUNK_SIZE - 1)
               {
                  bBelow = Blocks[x][y+1][z].IsActive();
               } else bBelow = false;
               bFront = bDefault;
               if(z > 0)
               {
                  bFront = Blocks[x][y][z-1].IsActive();
               } else bFront = false;
               bBack = bDefault;
               if(z < Chunk.CHUNK_SIZE - 1)
               {
                  bBack = Blocks[x][y][z+1].IsActive();
               } else bBack = false;
               
               boolean bResult = bLeft & bRight & bAbove &
                               bBelow & bFront & bBack;
               
               if(!bResult) // Block is not hidden by neighbouring blocks
              {
                  tx = ((xOffset * Chunk.CHUNK_SIZE) ) + (x);// << 1);
                      ty = ((yOffset * Chunk.CHUNK_SIZE) ) + (y);// << 1);
                      tz = ((zOffset * Chunk.CHUNK_SIZE) ) + (z);// << 1);
                 
//                     GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
             
                  renderBlock(GetBlock(x,y,z).getType());
             
                  iBlockCount++;   // total of blocks that can be seen
              }
               else
                  iHidden++;   // amount of blocks that are surrounded
           }
         }
      }
      glEnd();
       glDisable(GL11.GL_CULL_FACE);

      return iBlockCount;

   }


Yep, no translation thanks to @Longor1996 trick. 

In this line:

TextureBuffer texture = TextureManager.getInstance().getTexture(t);

t is the block type - grass, dirt etc and is pulled out of my hashmap, I use this
as the key.

Do you think the binding is the issue?

Thanks
Online mojo
« Reply #7 - Posted 2013-03-31 20:17:47 »

The GL11.glTexImage2D part looks suspicious.
Edit: Nevermind, Riven is right.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 757
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2013-03-31 20:19:11 »

Second time... please pay attention:

External code probably sets glBegin once, while for each block, you call glEnd. Therefore only the first block is rendered.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline steg90

Senior Member


Medals: 1



« Reply #9 - Posted 2013-03-31 20:31:19 »

@Riven - I've put the glBegin in like so now:

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  
private int createChunkList() {

      tx = 0; ty = 0; tz = 0;
      int iHidden = 0;
      int iBlockCount = 0;
      boolean bLeft = !false;
      boolean bRight = !false;
      boolean bAbove = !false;
      boolean bBelow = !false;
      boolean bFront = !false;
      boolean bBack = !false;

      boolean bDefault = true;
     
       glEnable(GL11.GL_CULL_FACE);

      for (int x = 0; x < Chunk.CHUNK_SIZE; x++) {
         for (int y = 0; y < Chunk.CHUNK_SIZE; y++) {
            for (int z = 0; z < Chunk.CHUNK_SIZE; z++) {
                         
                                        GL11.glEnable(GL_TEXTURE_2D);
               glBegin(GL11.GL_QUADS);  // placed here

               if(!GetBlock(x,y,z).IsActive())  //
              {
                  continue;
               }
               bLeft = bDefault;
               if(x > 0)
               {
                  bLeft = Blocks[x-1][y][z].IsActive();
               } else bLeft = false;
               bRight = bDefault;
               if(x < Chunk.CHUNK_SIZE - 1)
               {
                  bRight = Blocks[x+1][y][z].IsActive();
               } else bRight = false;
               bAbove = bDefault;
               if(y > 0)
               {
                  bAbove = Blocks[x][y-1][z].IsActive();
               } else bAbove = false;
               bBelow = bDefault;
               if(y < Chunk.CHUNK_SIZE - 1)
               {
                  bBelow = Blocks[x][y+1][z].IsActive();
               } else bBelow = false;
               bFront = bDefault;
               if(z > 0)
               {
                  bFront = Blocks[x][y][z-1].IsActive();
               } else bFront = false;
               bBack = bDefault;
               if(z < Chunk.CHUNK_SIZE - 1)
               {
                  bBack = Blocks[x][y][z+1].IsActive();
               } else bBack = false;
               
               boolean bResult = bLeft & bRight & bAbove &
                               bBelow & bFront & bBack;
               
               if(!bResult) // Block is not hidden by neighbouring blocks
              {
                  tx = ((xOffset * Chunk.CHUNK_SIZE) ) + (x);// << 1);
                      ty = ((yOffset * Chunk.CHUNK_SIZE) ) + (y);// << 1);
                      tz = ((zOffset * Chunk.CHUNK_SIZE) ) + (z);// << 1);
                 
//                     GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
             
                  renderBlock(GetBlock(x,y,z).getType());
             
                  iBlockCount++;   // total of blocks that can be seen
              }
               else
                  iHidden++;   // amount of blocks that are surrounded
           //glEnd();
           }
         }
      }
      glEnd();
       glDisable(GL11.GL_CULL_FACE);

      return iBlockCount;

   }


Also had to add the enable texture, but now very very slow, maybe this is the binding you mentioned?

Regards,
Steve
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Member


Medals: 1



« Reply #10 - Posted 2013-03-31 20:45:09 »

On inspection, it is this line in renderBlock that is taking up all the processing time:

1  
2  
3  
4  
5  
6  
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 
            texture.decoder.getWidth(),
            texture.decoder.getHeight(),
            0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE,
            texture.buf);


This needs removing - well, needs sorting out how I do this so not done in the render loop...

Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #11 - Posted 2013-03-31 20:47:43 »

I once had 884 textures with dimensions 20*20 pixel rendered in one frame. Every single one with a call to bind(). And the FPS were down to 7 on my Intel Core i3 M330 with Radeon HD5650. Having many bind() calls is not good.
Offline steg90

Senior Member


Medals: 1



« Reply #12 - Posted 2013-03-31 20:49:42 »

Thanks Sparky but the bind doesn't seem to be the issue, if I remove the glTexImage2D call from the renderBlock code I 60fps again, but of course, not the correct texture.

Offline steg90

Senior Member


Medals: 1



« Reply #13 - Posted 2013-03-31 20:58:35 »

@Sparky83 - when do you call glTexImage2D?  I am obviously doing this badly as it shouldn't be in my renderBlock method.

Thanks
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #14 - Posted 2013-03-31 21:02:18 »

I just did this once in this method, which is loading a texture out of a PNG.

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  
private Texture loadTexture(String path){
      int width = 0;
      int height = 0;
      int id = 0;
      PNGDecoder decoder = null;
      InputStream stream = null;
      ByteBuffer buff;
      Texture tD = null;
      stream = ClassLoader.getSystemResourceAsStream(path);
     
      try {
         
         decoder = new PNGDecoder(stream);
     
         // read image size
        width = decoder.getWidth();
         height = decoder.getHeight();
         
         // pixel data size
        int bpp = 4;
         
         // create buffer for storage
        buff = BufferUtils.createByteBuffer(width * height * bpp);
         
         decoder.decode(buff, bpp * width, PNGDecoder.Format.RGBA);
         
         buff.flip();
         
         // create the texture from RGBA buffer
        GL11.glEnable(GL11.GL_TEXTURE_2D);
         
         id = GL11.glGenTextures();
         GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
   
         GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
         GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
               
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
         
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
         
         GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
         
         // store data
        tD = new Texture(id, width, height);
         if(stream != null)
            stream.close();
         
      } catch (IOException e1) { e1.printStackTrace(); }
     
      return tD;
   }

EDIT: for credit: I think this is out of a tutorial. May be from ClickerMonkey of davedes.
Offline steg90

Senior Member


Medals: 1



« Reply #15 - Posted 2013-03-31 21:04:43 »

Thanks for that,

And then with the Texture returned, is that what you bind with when you want to use it?

I'm just confused as to how you use the texture when it is loaded?

Thanks again
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #16 - Posted 2013-03-31 21:11:34 »

I usually have a wrapper class for that, that I call Image. Every Image get's stored in a hasmap when loaded:
1  
private HashMap<String,Image> dataBase; // attribute in my TextureManager class

Adding a texture is done with this method:
1  
2  
3  
4  
5  
6  
7  
8  
   public void addTexture(String name, String path){
      if(dataBase.containsKey(name))
         System.err.println("Image with key " + name + " already in database!");
      else{
         Texture tex = loadTexture(path);
         dataBase.put(name, new Image(tex));
      }
   }

And getting an Image back from the textureManager with this method:
1  
2  
3  
public Image getImage(String name){
      return dataBase.get(name);
   }


Every Image then has some methods to obtain any data like the corresponding texture ID or things like that. Of course images can be drawn with this method:
1  
2  
3  
4  
public void draw(SpriteBatch batch, float x, float y, float z, int f){
      frame = f;
      batch.draw(this, (int)x, (int)y, z);
   }

As you see, a SpriteBatch is needed for this. The SpriteBatch class then does binding for the texture.
This system is some work and takes some time to be done, but it is a huge help.
Offline steg90

Senior Member


Medals: 1



« Reply #17 - Posted 2013-03-31 21:16:38 »

Yeah I have something similiar to that with my TextureManager, but where does Texture object come from?  I'm trying to instantiate one like you but getting an error saying I cannot instantiate this object?  Which are you using, the slick util one?

Is it texture that gets bound in your render block code?

Sorry for all the questions, just getting a tad confused.
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #18 - Posted 2013-03-31 21:24:35 »

I have to add, that I am confusing a few things here, because I was usually working in 2D environments:
At the moment I am not using any batch class for textures. I am manually binding them with my TextureManager.

Here is what I do in my Chunk class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
// texture stuff
     TextureManager tM = TextureManager.getTextureManager();
      if(tM.getTexture("tex") == null){
         tM.addTexture("tex", "img/testTextur.png");
         tM.addTexture("tex2", "img/testTextur2.png");
         tM.addTexture("controls", "img/controls_eng.png");
      }
      tex = tM.getImage("tex2"); // tex is an attribute of type Image
     tM.bind(tex);

This sets up two box textures (Textur is not misspelled, this is in german, btw) and the controls info screen for the start of my alpha demo.

Then you wanted to know about how I get my textures working.
I got a pretty small class I called Texture. As you see, it contains some needed information about the texture:
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  
import org.lwjgl.opengl.GL11;

public class Texture{
   
   private int texID;
   private int width;
   private int height;
   
   public Texture(int id, int w, int h){
      texID = id;
      width = w;
      height = h;
   }
   
   public int getImageWidth(){
      return width;
   }
   
   public int getImageHeight(){
      return height;
   }
   
   public int getTextureID(){
      return texID;
   }
   
   public void release(){
      GL11.glDeleteTextures(texID);
   }
}

This is just inspired by slickUtil. But I am not using slick anymore.

And as I previously said, the Texture gets wrapped in my Image class. This happens here:
1  
2  
3  
4  
5  
6  
7  
8  
public void addTexture(String name, String path){
      if(dataBase.containsKey(name))
         System.err.println("Image with key " + name + " already in database!");
      else{
         Texture tex = loadTexture(path);
         dataBase.put(name, new Image(tex)); // #### HERE ######## new Image(tex)
     }
   }
Offline steg90

Senior Member


Medals: 1



« Reply #19 - Posted 2013-03-31 21:40:42 »

Thanks again,

I now have it working, it was a lesson in learn to walk before I can run!  I'm new to OpenGL so really need to spend more time on some tutorials before jumping right in!

This is my new createChunkList method:

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  
private int createChunkList() {

      tx = 0; ty = 0; tz = 0;
      int iHidden = 0;
      int iBlockCount = 0;
      boolean bLeft = !false;
      boolean bRight = !false;
      boolean bAbove = !false;
      boolean bBelow = !false;
      boolean bFront = !false;
      boolean bBack = !false;

      boolean bDefault = true;
     
       glEnable(GL11.GL_CULL_FACE);
       GL11.glEnable(GL_TEXTURE_2D);

      TextureBuffer texture = TextureManager.getInstance().getTexture(BlockType.BlockType_Grass);
      GL11.glBindTexture(GL_TEXTURE_2D, texture.textureId);

      for (int x = 0; x < Chunk.CHUNK_SIZE; x++) {
         for (int y = 0; y < Chunk.CHUNK_SIZE; y++) {
            for (int z = 0; z < Chunk.CHUNK_SIZE; z++) {

               glBegin(GL11.GL_QUADS);
               
               if(!GetBlock(x,y,z).IsActive())  //
              {
                  continue;
               }
               bLeft = bDefault;
               if(x > 0)
               {
                  bLeft = Blocks[x-1][y][z].IsActive();
               } else bLeft = false;
               bRight = bDefault;
               if(x < Chunk.CHUNK_SIZE - 1)
               {
                  bRight = Blocks[x+1][y][z].IsActive();
               } else bRight = false;
               bAbove = bDefault;
               if(y > 0)
               {
                  bAbove = Blocks[x][y-1][z].IsActive();
               } else bAbove = false;
               bBelow = bDefault;
               if(y < Chunk.CHUNK_SIZE - 1)
               {
                  bBelow = Blocks[x][y+1][z].IsActive();
               } else bBelow = false;
               bFront = bDefault;
               if(z > 0)
               {
                  bFront = Blocks[x][y][z-1].IsActive();
               } else bFront = false;
               bBack = bDefault;
               if(z < Chunk.CHUNK_SIZE - 1)
               {
                  bBack = Blocks[x][y][z+1].IsActive();
               } else bBack = false;
               
               boolean bResult = bLeft & bRight & bAbove &
                               bBelow & bFront & bBack;
               
               if(!bResult) // Block is not hidden by neighbouring blocks
              {
                  tx = ((xOffset * Chunk.CHUNK_SIZE) ) + (x);// << 1);
                      ty = ((yOffset * Chunk.CHUNK_SIZE) ) + (y);// << 1);
                      tz = ((zOffset * Chunk.CHUNK_SIZE) ) + (z);// << 1);
                 
//                     GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
             
                  renderBlock(GetBlock(x,y,z).getType());
             
                  iBlockCount++;   // total of blocks that can be seen
              }
               else
                  iHidden++;   // amount of blocks that are surrounded
           
            }
         }
      }
      glEnd();
       glDisable(GL11.GL_CULL_FACE);

      return iBlockCount;

   }


Notice the call the my TextureManager to get the texture for a block type of grass - hard coded, but will sort out later.

My renderBlock method:

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  
private void renderBlock(Block.BlockType type) {
     
      GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, 0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, 0.5f);   // Top Left Of The Texture and Quad
     // Back Face
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, -0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, -0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, -0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, -0.5f);   // Bottom Left Of The Texture and Quad
     // Top Face
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, -0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f(-0.5f, 0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f( 0.5f, 0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, -0.5f);   // Top Right Of The Texture and Quad
     // Bottom Face
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f(-0.5f, -0.5f, -0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f( 0.5f, -0.5f, -0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     // Right face
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, -0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, -0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f( 0.5f, 0.5f, 0.5f);   // Top Left Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     // Left Face
     GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, -0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, 0.5f);   // Top Right Of The Texture and Quad
     GL11.glTexCoord2f(0.0f, 1.0f);
      off_glVertex3f(-0.5f, 0.5f, -0.5f);   // Top Left Of The Texture and Quad      
       GL11.glEnd();
        glColor3f(1,1,1);
   }


Note the removal of the loading the texture - what was I thinking?!?!

And in my 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  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
private boolean loadToolTexture(TextureBuffer tb, BlockType t)
         throws IOException {
      String texturePath = "";
      boolean bLoaded = true;
      try {
         switch (t) {
         case BlockType_Grass:
            texturePath = "grass16x16.png";
            break;
         case BlockType_Dirt:
            texturePath = "grassdirt.png";
            break;
         case BlockType_Wood:
            texturePath = "crate16x16.png";
            break;
         case BlockType_Stone:
            texturePath = "stone.png";
            break;
         case BlockType_Sand:
            texturePath = "sand.png";
            break;
         case BlockType_Water:
            texturePath = "water.png";
            break;
         case BlockType_Snow:
            texturePath = "snow.png";
            break;
         default:
            texturePath = "grass16x16.png";
         }
         in = new FileInputStream("res/" + texturePath);
         tb.decoder = new PNGDecoder(in);

         tb.buf = ByteBuffer.allocateDirect(4 * tb.decoder.getWidth()
               * tb.decoder.getHeight());
         tb.decoder.decode(tb.buf, tb.decoder.getWidth() * 4, Format.RGBA);
         tb.buf.flip();
         tb.textureId = GL11.glGenTextures();
         GL11.glEnable(GL11.GL_TEXTURE_2D);
         GL11.glBindTexture(GL_TEXTURE_2D, tb.textureId);
         GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
         GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);

         GL11.glTexParameteri(GL11.GL_TEXTURE_2D,
               GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D,
               GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S,
               GL11.GL_CLAMP);
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
               GL11.GL_CLAMP);

         GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA,
               tb.decoder.getWidth(), tb.decoder.getHeight(), 0,
               GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, tb.buf);
         

      } catch (Exception e) {
         System.out.println(e.getMessage());
         bLoaded = false;
      } finally {
         in.close();
      }
      return bLoaded;
   }


This loads the texture.

Need to check on the texture id also - to do, as it may already have been generated.

Many thanks for the help, and your raycasting looks cool on picking the blocks.  How did you do your collision checks with the blocks?  AABB's?

Thanks
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #20 - Posted 2013-03-31 21:52:54 »

Quote
Many thanks for the help, and your raycasting looks cool on picking the blocks.  How did you do your collision checks with the blocks?  AABB's?

Thanks
I have no collision testing in my released alpha. I am currently fixing some issues with it. Then I will update my thread. Smiley But it will be AABB/AABB collision testing.
Glad you like the raycasting. I am fascinated by it too. I guess you found the source for it in my thread. It may be helpful.

BTW: In your posted source you are still calling glEnd() after every rendered cube. Doesn't it work without this at this position?
Offline steg90

Senior Member


Medals: 1



« Reply #21 - Posted 2013-03-31 21:55:29 »

Any thoughts on how to optimize this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
for (int x = 0; x < Chunk.CHUNK_SIZE; x++) {
         for (int y = 0; y < Chunk.CHUNK_SIZE; y++) {
            for (int z = 0; z < Chunk.CHUNK_SIZE; z++) {
               Block block = GetBlock(x,y,z);
               TextureBuffer texture = TextureManager.getInstance().getTexture(block.getType());
               GL11.glBindTexture(GL_TEXTURE_2D, texture.textureId);

               glBegin(GL11.GL_QUADS);

// etc - render block


The glBindTexture is slowing the code down a little, if I move it out of the loop it is fine, but obviously all the blocks would show the same texture.

I guess it comes down to checking if texture has already been bound as previously mentioned in the thread?

Thanks
Offline steg90

Senior Member


Medals: 1



« Reply #22 - Posted 2013-03-31 21:57:31 »

Hi,

You mean the glEnd in my createChunkList code?  All works with it where it is?

Yep, raycasting looks cool, how do you get the direction the player is facing, this some
simple trig?

Just wanting to optimize the binding of different textures....
Offline Longor1996
« Reply #23 - Posted 2013-03-31 22:02:12 »

@steg90

You are making three major mistakes:
1. The off_vertex method never get's it's tx/ty/tz values.
2. You are not using a single texture for the block textures.
3. You are using glBegin/glEnd wrong (Wrong placed).

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #24 - Posted 2013-03-31 22:09:00 »

Hi,

You mean the glEnd in my createChunkList code?  All works with it where it is?

No, like Riven said:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
private void renderBlock(Block.BlockType type) {
     
      GL11.glTexCoord2f(0.0f, 0.0f);
      off_glVertex3f(-0.5f, -0.5f, 0.5f);   // Bottom Left Of The Texture and Quad
     GL11.glTexCoord2f(1.0f, 0.0f);
      off_glVertex3f( 0.5f, -0.5f, 0.5f);   // Bottom Right Of The Texture and Quad
    [...]
      off_glVertex3f(-0.5f, 0.5f, -0.5f);   // Top Left Of The Texture and Quad      
       GL11.glEnd(); // this one here ########################
       glColor3f(1,1,1);
   }


Quote
Yep, raycasting looks cool, how do you get the direction the player is facing, this some
simple trig?
I have made my own Ray class and it takes an origin of Vector3 and a uniform delta of Vector3. Then the uniform vector gets scaled by scalarProduct.
1  
2  
3  
4  
5  
uniRay.setPosition(-pos.getX(),-pos.getY(),-pos.getZ());
      uniRay.setDelta((float)Math.sin(Math.toRadians(-rotY))*(float)-Math.cos(Math.toRadians(-rotX)),
                           (float)Math.sin(Math.toRadians(-rotX)),
                           (float)-Math.cos(Math.toRadians(-rotY))*(float)Math.cos(Math.toRadians(-rotX)));
      uniRay.scalarProduct(RAY_LENGTH); // change length of the uniform vector

The rotX variables are the rotation in degrees on every axis by the player.
Offline steg90

Senior Member


Medals: 1



« Reply #25 - Posted 2013-03-31 22:10:16 »

@Longor1996

1. The off_vertex does get the tx/ty/tz values ?!

2. Single texture for the block textures - you mean I'm binding them again?? Or have one big texture which has multiple textures in it?

3. glBegin / glEnd - in my createChunkList method?  

I appreciate your advice @Longor1996
Offline steg90

Senior Member


Medals: 1



« Reply #26 - Posted 2013-03-31 22:13:28 »

Oops, lol, removed it now.  Thanks for pointing it out guys. 

You have lost me with the ray class, guess I need to research some ray cast stuff, is the game math book any good, I notice there is a new edition?
Offline Longor1996
« Reply #27 - Posted 2013-03-31 22:14:47 »

Hi.

@Longor1996

1. The off_vertex does get the tx/ty/tz values ?!

2. Single texture for the block textures - you mean I'm binding them again?? Or have one big texture which has multiple textures in it?

3. glBegin / glEnd - in my createChunkList method?  

I appreciate your advice @Longor1996

1. Where? I can't see any getter/setter that sets the values for the method.
2. Yep. Multiple textures in a single Texture. This is the way to go. (Google: Tile Atlas/Map)
3. Yep. You are using them wrong. You only need one at the beginning of the nested loop that draws the blocks, and at the end of the nested loop.


4. Thanks!

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline Sparky83

Senior Member


Medals: 6
Projects: 1



« Reply #28 - Posted 2013-03-31 22:15:50 »

If you really study math with this one, you will be up to the task of 3D game programming.
http://gamemath.com/about-the-book/

I am not advertising, I just love this book as it helped me so much btw. Smiley
But you can of course also do it without it.
Offline steg90

Senior Member


Medals: 1



« Reply #29 - Posted 2013-03-31 22:42:37 »

@Sparky83 I will get that book :-)

@Longor1996 - I originally use to have the glBegin out of the nested loops, my issue is needing to bind the texture before the glBegin and to do that I use:

GetBlock(x,y,z);

1  
2  
3  
4  
5  
6  
7  
8  
for (int x = 0; x < Chunk.CHUNK_SIZE; x++) {
         for (int y = 0; y < Chunk.CHUNK_SIZE; y++) {
            for (int z = 0; z < Chunk.CHUNK_SIZE; z++) {
               Block block = GetBlock(x,y,z);
               TextureBuffer texture = TextureManager.getInstance().getTexture(block.getType());
               GL11.glBindTexture(GL_TEXTURE_2D, texture.textureId);

               glBegin(GL11.GL_QUADS);


Need another way of getting the current block in order to get its texture id so I can bind its texture before the glBegin...

Is there a way of binding a texture to a block before the above stage?

Thanks
Pages: [1] 2
  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.

CogWheelz (15 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (15 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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
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!