Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  How to add vertices to VBO?  (Read 1733 times)
0 Members and 1 Guest are viewing this topic.
Offline Doubstract
« Posted 2013-12-27 12:48:49 »

How to add vertices to VBO? Currently i am trying to do something like this:


FLOATBUFFER:
1  
public static FloatBuffer vertices = BufferUtils.createFloatBuffer(2*4*4);



ADDING TWO QUADS:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
 vertices.put(new float[]
        {
            0,   0,
            0+200, 0,
            0+200, 0+200,
            0, 0+200,
           300,   300,
            300+200, 300,
           300+200, 300+200,
            300,  300+200
        });
        vertices.rewind();


 vboVertexID = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
        glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);



DRAWING:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);

                  glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
                   glVertexPointer(2, GL_FLOAT, 0, 0);
                   glDrawArrays(GL_QUADS, 0, 16);

            glDisableClientState(GL_VERTEX_ARRAY);
            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
       
           
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #1 - Posted 2013-12-27 12:54:51 »

  • 1. What are you trying to draw?
  • 2. Why are you filling the buffer with 16 vertices but giving it a size of 32?
  • 3. Put an f after all your numbers.

Why are all OpenGL tutorials written in Brainf**k?
Offline Doubstract
« Reply #2 - Posted 2013-12-27 13:08:37 »

1. i am just trying to draw anything, i am learning VBO.
2. i want to add more vertices, so i think i need free space.
3. thanks for tip Smiley


I found a way how i can add vertices, but i think its not right way:
1  
public static float[] floats = new float[32]; 


1  
2  
3  
4  
5  
6  
public void verticesTick(){
vertices.put(floats);
      vertices.rewind();
      glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
        glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
}


With this i can modify my floats array and change my VBO, but i am doing this every tick, i think its problem.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #3 - Posted 2013-12-27 13:56:49 »

You use VBOs to try and keep vertex data on the GPU (graphics processing unit) for as long as possible so that you don't have to keep updating the data constantly. You'll want to start off by creating an initialize method which creates the VBO. If you wanted to draw a triangle you'd have something like this:

To create and fill the buffer object with data-
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void initialize() {
   // when rendering, if this is enabled then glDrawArrays will look at the information stored by glVertexPointer or glVertexAttribPointer (which is introduced in newer OpenGL versions)
   glEnableClientState(GL_VERTEX_ARRAY);

   float[] data = {
         -0.5f, -0.5f, 0f // bottom left
         -0.5f, +0.5f, 0f // top left
         +0.5f, -0.5f, 0f // bottom right
   };

   vboVertexID = glGenBuffers(); // generates the handle (id) used to bind the buffer
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexID); // binds the handle to the target GL_ARRAY_BUFFER
   // fills the most recently bound buffer (vboVertexID) with data. the usage (GL_STATIC_DRAW) indicates that the buffer data will be used for drawing and won't be changed directly
   glBufferData(GL_ARRAY_BUFFER, (FloatBuffer) BufferUtils.createFloatBuffer(data.length).put(data).flip() /* the buffer is flipped so that it draws from position 0 */, GL_STATIC_DRAW);
   glBindBuffer(GL_ARRAY_BUFFER, 0); // unbinds the most recently bound buffer (vboVertexID) from the target GL_ARRAY_BUFFER
}


The game loop- a simple game loop would look something like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void loop() {
   initialize();

   while(!Display.isCloseRequested()) {
      Display.sync(60); //fps
      updateGameLogic();

      if(Display.isVisible || Display.isDirty) {
         render();
         Display.update();
      }
   }

   dispose(); // when closed, delete vbos with glDeleteBuffer(handle)
}


Rendering-
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  
public void render() {
   glClearColor(0f, 0f, 0f, 1f); // colour to clear the screen; r, g, b, a
   glClear(GL_COLOR_BUFFER_BIT); // clears the colour buffer (the screen)

   glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
   
    /*
    * glVertexPointer(size, type, stride, offset) DEPRECATED in newer OpenGL versions
    *
    * The arguments given to this function represent how the data in a
    * buffer is stored. The given arguments are saved in memory. The size
    * is the number of attributes per vertex (3D space means there are 3
    * attributes). The type is the data type of each attribute. The stride is
    * the number of bytes per vertex - float has 4 bytes so it should be
    * 3(size)*4, however a value of 0 tells OpenGL that the data is tightly
    * packed. The offset is the number of bytes between the start of the
    * buffer and the first attribute.
    */

   glVertexPointer(3, GL_FLOAT, 3 << 2, 0); // 3 is represented in bytes as 0011. shifting the bits 2 to the left changes it to 1100 which represents 12. 3 << 2 effectively means 3*4.

   /*
    * glDrawArrays(mode, first, count)
    *
    * Renders the shape. If the various states are enabled it will get the
    * associated data from memory, e.g if GL_VERTEX_ARRAY is enabled it
    * will get the data from memory assigned by glVertexPointer(...). The
    * mode specifies what kind of geometric primitives (shapes) to render.
    * The first is the starting position of the vertices to render in the bound
    * buffer. The count specifies the number of vertices to render.
    */

   glDrawArrays(GL_TRIANGLES, 0, 3);
   glBindBuffer(GL_ARRAY_BUFFER, 0);
}


If you don't understand something just ask and I'll explain it.

Why are all OpenGL tutorials written in Brainf**k?
Offline Doubstract
« Reply #4 - Posted 2013-12-27 15:01:07 »

its great explanation, but you said this line:
1  
 glVertexPointer(3, GL_FLOAT, 3 << 2, 0);

is deprecated, so how new version should like?

And if you can, i would like to see how i can draw quad in 2 dimensions. i tried to do that, but i am getting really strange results.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #5 - Posted 2013-12-27 15:14:48 »

Don't worry about using deprecated functions yet, but for reference, in V2.0 you would use shaders and instead use glVertexAttribPointer. To draw a quad, create a buffer and fill it with 12 attributes (3 per vertex). The for a square the vertices would be:

1  
2  
3  
4  
5  
6  
float[] data = {
    -0.5f, -0.5f, 0f // bottom left
    -0.5f, +0.5f, 0f // top left
    +0.5f, +0.5f, 0f // top right
    +0.5f, -0.5f, 0f // bottom right
};


1  
glVertexPointer(3, GL_FLOAT, 3 << 2, 0)

These parameters would be the same since each vertex still has 3 attributes and the data is still formatted in the same way in the buffer.

However you have two options for glDrawArrays(). You could draw it with the mode GL_TRIANGLE_STRIP which is preferred for 3D models. You'd need to put a count of 4 since you have 4 vertices like so:
1  
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


Or you could draw it with the mode GL_QUADS which is preferred for a single quad, again using a count of 4.
1  
glDrawArrays(GL_QUADS, 0, 4);


This image displays all the possible modes

Why are all OpenGL tutorials written in Brainf**k?
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #6 - Posted 2013-12-27 16:48:28 »

However, do note that quads are not the best type to use. Triangles are better because the GPU breaks geometry down into triangles, so why give it extra work to do when using quads? Its a very small change, but worth it.

Offline Doubstract
« Reply #7 - Posted 2013-12-28 08:24:55 »

Thanks for answers! But now i am trying to put 2 quads in VBO and draw only second quad, but i am getting strange results:

VBO DATA:

1  
   public static float[] data = new float[24];


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  
public void initialize() {
         glEnableClientState(GL_VERTEX_ARRAY);

         
         data[0] = 100;
         data[1] = 100;
         data[2] = 0;
         data[3] = 400;
         data[4] = 100;
         data[5] = 0;
         data[6] = 100;
         data[7] = 400;
         data[8] = 0;
         data[9] = 400;
         data[10] = 400;
         data[11] = 0;
         
         data[12] = 100+ 300;
         data[13] = 100+ 300;
         data[14] = 0;
         data[15] = 200+ 300;
         data[16] = 100+ 300;
         data[17] = 0;
         data[18] = 100+ 300;
         data[19] = 200+ 300;
         data[20] = 0;
         data[21] = 200+ 300;
         data[22] = 200+ 300;
         data[23] = 0;
     
         //data[24] = 200 + 300;
        // data[25] = 200 + 300;
        // data[26] = 0;
         vboVertexID = glGenBuffers();
         glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
         glBufferData(GL_ARRAY_BUFFER, (FloatBuffer) BufferUtils.createFloatBuffer(data.length).put(data).flip() , GL_STATIC_DRAW);
         glBindBuffer(GL_ARRAY_BUFFER, 0);
      }

I think this code is more or less good enough to render second quad.




RENDERING METHOD:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void render() {
         glClearColor(1f, 1f, 1f, 1f);
         glClear(GL_COLOR_BUFFER_BIT);

         glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
         
   
         glVertexPointer(3, GL_FLOAT, 3 << 2, 0);

         GL11.glColor3f(0,0, 0);
     
         
         glDrawArrays(GL_TRIANGLE_STRIP,0,8);
         
         glBindBuffer(GL_ARRAY_BUFFER, 0);
      }



And everything is ok, but when i change my rendering method to this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void render() {
         glClearColor(1f, 1f, 1f, 1f);
         glClear(GL_COLOR_BUFFER_BIT);

         glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
         
   
         glVertexPointer(3, GL_FLOAT, 3 << 2, 0);

         GL11.glColor3f(0,0, 0);
     
         
         glDrawArrays(GL_TRIANGLE_STRIP,4,8);
         
         glBindBuffer(GL_ARRAY_BUFFER, 0);
      }


I get this:



How i can fix this problem?


EDIT:
i found one solution, i can change
1  
glDrawArrays(GL_TRIANGLE_STRIP,4,8);

to this:
1  
glDrawArrays(GL_TRIANGLE_STRIP,4,4);

And its works good, it is best solution?
Offline StumpyStrust
« Reply #8 - Posted 2013-12-28 08:35:04 »

Off topic sorry: I have seen no difference in performance when using quads vs 2 triangles. I think this is because the driver will turn a quad into triangles itself as I can only draw them. Not saying you should only do quads for sprites/what ever but I do not think there is a substantial performance gain. If you are using indices for static data, that is a different story.

Online trollwarrior1
« Reply #9 - Posted 2013-12-28 08:45:07 »

For any 2d game quads are more than enough. Not sure about 3d games where there are massive polygon/triangle counts.

I converted one of my games from triangles to quads and didn't get ANY performance gain whatsoever. Just stick with quads for 2d games. Less stuff to handle by yourself.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Doubstract
« Reply #10 - Posted 2013-12-28 09:12:01 »

I agree, quads enough for 2d, but if i want to make particles system with VBO, i think triangles is much more better, so where is problem in here?
Offline Doubstract
« Reply #11 - Posted 2013-12-28 11:59:43 »

I dont care it anymore, i just changed it to quads.

New question:
How to add textures?
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #12 - Posted 2013-12-28 12:55:08 »

Off topic sorry: I have seen no difference in performance when using quads vs 2 triangles. I think this is because the driver will turn a quad into triangles itself as I can only draw them. Not saying you should only do quads for sprites/what ever but I do not think there is a substantial performance gain. If you are using indices for static data, that is a different story.
Oh, I know. I barely ever use triangles either, but I just wanted to let OP know so that he was informed about the "standards".

As for texturing, you'll need to create another FloatBuffer to store the texture coordinates. It's actually almost the same process as what you just went through. But please, please just use Google and try it yourself. You'll learn a lot.

Offline Doubstract
« Reply #13 - Posted 2013-12-28 13:30:10 »

Google is useless in my opinion, i cant find anything usefull.

I am trying to create platformer with tiles, and i want to store my tiles in chunks. And now i am thinking, it is possible to have chunk with 16*16 tiles and each tile with different texture?
Offline StrideColossus
« Reply #14 - Posted 2013-12-28 13:40:32 »

Yes it's possible.  There are several options but perhaps the best approach is use one texture per chunk with the tile images packed into that: The tiles would be arranged as a 4x4 grid and your chunk would be a 4x4 grid of indices into that texture.

This means you have a single mesh and only one texture state change per chunk.

Depending on your game and how big the chunks/tiles are this could be extended to have a larger texture grid covering multiple chunks, e.g. you could store all the tiles in a single texture and just have one mesh for the entire scene.

- stride
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #15 - Posted 2013-12-28 13:52:31 »

Google is useless in my opinion, i cant find anything usefull.

I am trying to create platformer with tiles, and i want to store my tiles in chunks. And now i am thinking, it is possible to have chunk with 16*16 tiles and each tile with different texture?
Have you ever played a platformer? Then yes, it's possible.

Have you ever used textures in OpenGL before? It's very easy to convert everything over to a buffer object. You'll need to have a spritesheet though.

Offline Doubstract
« Reply #16 - Posted 2013-12-28 13:59:20 »

Quote
Have you ever played a platformer? Then yes, it's possible.

Have you ever used textures in OpenGL before? It's very easy to convert everything over to a buffer object. You'll need to have a spritesheet though.

I mean i want to change textures using VBO
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #17 - Posted 2013-12-28 14:01:26 »

A "VBO" is just a buffer object. It doesn't do much more than fill itself with data. You cannot "change textures using VBO". If you mean you want a texture per buffer object, than you won't have to mess with spritesheets. I think you need to clarify more so we can understand what you want.

Offline Doubstract
« Reply #18 - Posted 2013-12-28 14:13:53 »

I want to use something like this:
1  
 glTexCoordPointer(2, GL_FLOAT, 0, 0);
To add textures, and i have chunks with 16*16 tiles.
I want each tile with different texture
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #19 - Posted 2013-12-28 14:33:11 »

Then you'll need a spritesheet. Generate your texture coordinates within the range of 0 - 1 (obviously) and then put them in a FloatBuffer. Each tile type will have it's own "unique" set of coordinates. Then find out how to render textures using buffer objects (VBOs).

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #20 - Posted 2013-12-28 14:36:41 »

But please, please just use Google and try it yourself. You'll learn a lot.

Although you can learn a lot from using Google, I find that some of the jargon you come across isn't explained properly, which leads to having to search up a lot more terms. Also, most of the code you find is C or C++ relate which can be a problem if you don't know those languages.


Going back to your question on glDrawArrays:

Here you're telling it to start rendering from position 4 in the buffer object. However, you're still telling it to draw 8 vertices.
1  
glDrawArrays(GL_TRIANGLE_STRIP,4,8);

Here however you are telling it to start rendering from position 4 in the buffer and you are telling it to draw 4 vertices.
1  
glDrawArrays(GL_TRIANGLE_STRIP,4,4);

So yes, that's the correct way to do it.

Textures:

Since I can't be bothered writing out all the code for creating a texture, let me point you to this great tutorial on textures for LWJGL. It teaches you how to decode a PNG into a byte buffer and how to create a texture. It also teaches you about texture coordinates and texture wrapping. If you don't want to use a library for decoding a texture, I'll lead you to this tutorial by SHC which has the code for decoding a PNG image with the Java API.

If you want to add textures it's probably best to use an interleaved buffer object. An interleaved buffer object is a buffer object where the data for both the vertices, and in this case the texture co-ordinates, is held in the same buffer. A texture coordinate is defined as a vector in tanget space, much like a vertex is defined as a vector in 3D space. The difference is however that tangent space represents direction and has a coordinate system of [s, t] or [u, v], whereas 3D space represents a position and is defined as [x, y, z]. Texture coordinates should be defined as 0 >= 1.



So first of all lets set up a basic interleaved buffer object which holds vertices and texture coordinates. If you have a co-ordinate system where (0, 0) is the top left you will need to change the texture coordinates, with [0, 0] being the top left.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
float[] data = {
   -0.5f, -0.5f, 0f, // bottom left
   0f, 0f, // bottom left
   -0.5f, 0.5f, 0f, // top left
   0f, 1f, // top left
   0.5f, -0.5f, 0f, // bottom right
   1f, 0f, // bottom right
   0.5f, 0.5f, 0f, // top right
   1f, 1f}; // top right

glEnable(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D); // enable textures

bufferId = glGenBuffers();

glBindBuffer(GL_ARRAY_BUFFER, bufferId);
glBufferData(GL_ARRAY_BUFFER, (FloatBuffer) BufferUtils.createFloatBuffer(20).put(data).flip(), GL_STATIC_DRAW)
glBindBuffer(GL_ARRAY_BUFFER, 0);


If you haven't yet set up your texture, read the tutorial I linked to above.

Now for the render method.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
glClearColor(0f, 0f, 0f, 1f); // set the clear colour as usual
glClear(GL_COLOR_BUFFER_BIT); // clear the colour buffer (screen)

glBindBuffer(GL_ARRAY_BUFFER, bufferId);
glBindTexture(GL_TEXTURE_2D, textureId);
glVertexPointer(3, GL_FLOAT, 5 << 2, 0); // there is a stride of 5 << 2, i.e every 5 float values there is a new vertex position
glTexCoordPointer(2, GL_FLOAT, 5 << 2, 3 << 2); // every 2 float values is a texture coordinate. there is a stride of 5 << 2 and an offset of 3 << 2, i.e after 3 float values the first texture coordinate begins
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // there are 4 vertices to draw
glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);


Note: glTexCoordPointer has the same parameters as glVertexPointer. If you don't understand something just ask. Smiley

Why are all OpenGL tutorials written in Brainf**k?
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #21 - Posted 2013-12-28 14:39:28 »

Why are you using strides? I don't think there's much of a point of doing that?

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #22 - Posted 2013-12-28 14:41:14 »

Why are you using strides? I don't think there's much of a point of doing that?

Why not? There are less buffers to bind and less buffers to create, overall saving space on the GPU.

EDIT: If you meant why not format is as VVVVTTTT, it's because I prefer to format it as VTVTVTVT. However as a reference for the OP, if you wanted to format the buffer as VVVVTTTT, you'd change your stride and offset to:

1  
2  
glVertexPointer(3, GL_FLOAT, 3 << 2, 0);
glTexCoordPointer(2, GL_FLOAT, 2 << 2, 12 << 2) // there would be 2 << 2 bytes between each texture coordinate vector. there would be 12 << 2 bytes between the beginning of the buffer and the start of the first texture coordinate

Why are all OpenGL tutorials written in Brainf**k?
Offline Dxu1994
« Reply #23 - Posted 2013-12-28 15:17:05 »

Just use GL_TRIANGLES with an index buffer to render sprites, using GL_QUADS is not only pointless as your driver can only render triangles in the first place, its also not portable to ES (if you ever want to make a mobile version)

Offline davedes
« Reply #24 - Posted 2013-12-28 15:17:22 »

If you specify 0 as stride it tells OpenGL that things are "tightly packed."

All of these struggles just makes me wonder why OP doesn't use LibGDX... Smiley You can achieve the same thing in a fraction of the time, with far less headache.
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Meshes

You can just use their vertex/index buffer utilities to avoid the low-level GL debugging which is usually a pain in the ass.

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #25 - Posted 2013-12-28 16:33:45 »

If you specify 0 as stride it tells OpenGL that things are "tightly packed."

All of these struggles just makes me wonder why OP doesn't use LibGDX... Smiley You can achieve the same thing in a fraction of the time, with far less headache.
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Meshes

You can just use their vertex/index buffer utilities to avoid the low-level GL debugging which is usually a pain in the ass.

Specifying 0 as the stride forces OpenGL to calculate the correct stride. Calculating strides yourself isn't only good practice but gets you used to calculating strides when you need to.

Sure, the OP could use LibGDX but maybe the OP wants to learn OpenGL in the process.

Why are all OpenGL tutorials written in Brainf**k?
Offline davedes
« Reply #26 - Posted 2013-12-28 17:22:34 »

Quote
forces OpenGL to calculate the correct stride
The performance difference is negligible. You may as well let OpenGL do it for you.

Quote
Sure, the OP could use LibGDX but maybe the OP wants to learn OpenGL in the process.
I'd argue it's much easier to learn OpenGL and graphics programming by using a library, rather than writing boilerplate.

Learning how to write boilerplate doesn't make you a good graphics programmer. It just means you know how to write the boilerplate. Programmers only write boilerplate once, and then they create abstractions on top of it. Once you have a firm grasp of the entire pipeline, it will be easier to tinker with the boilerplate if you ever find a need to (which is very rare).

But that's just my opinion, after many years of graphics programming. Smiley

Offline Doubstract
« Reply #27 - Posted 2013-12-29 08:57:17 »

For some reason i cant apply texture normal, whole quad just fills texture first pixel color.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #28 - Posted 2013-12-29 08:59:05 »

Show us some code. Smiley

Why are all OpenGL tutorials written in Brainf**k?
Offline Doubstract
« Reply #29 - Posted 2013-12-29 09:05:54 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
 float[] datatex = {
               100, 500, 0f,
               100, 100, 0f,
               500, 500, 0f,
               500, 100, 0f,
               0f, 0f,
               0f, 1f,
               1f, 0f,
               1f, 1f};



1  
2  
3  
4  
5  
6  
7  
glBindBuffer(GL_ARRAY_BUFFER, bufferId);
      glBindTexture(GL_TEXTURE_2D, texture.id);
      glVertexPointer(3, GL_FLOAT, 3 << 2, 0);
      glTexCoordPointer(2, GL_FLOAT, 2 << 2, 12 << 2); vector.
      glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
      glBindTexture(GL_TEXTURE_2D, 0);
      glBindBuffer(GL_ARRAY_BUFFER, 0);

I think this enough.


And thanks everyone for answers Smiley.

EDIT:
i tried it with immediate mode, everything worked perfect
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (42 views)
2014-10-16 15:22:06

Norakomi (32 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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