Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  Faster transformation with VBOS  (Read 1219 times)
0 Members and 1 Guest are viewing this topic.
Offline lcass
« Posted 2014-04-12 20:24:17 »

Hello, im attempting to use a transformation method to modify my VBOS however I would like to know what toher way I can edit the positions within the VBO without having to create it again. This is how I am doing it at the moment. I get 30fps doing 10000 transformations.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   public void translate(int x, int y) {
      verticies.clear();
      for (int i = 0; i < position.length; i++) {
         float cx = position[i].getx();
         float cy = position[i].gety();
         verticies.put(cx + x);
         verticies.put(cy + y);
         position[i].setcoordinates(cx + x, cy + y);
      }
      verticies.rewind();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticies, GL15.GL_DYNAMIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
   }


EDIT:
Note is that position is an array of vertex2d objects (not OpenGL ones).
Offline Longarmx
« Reply #1 - Posted 2014-04-12 20:44:52 »

The easiest and probably fastest way to do this would be to do this in a vertex shader for constantly updating data.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
// Modifies the matrix to translate
public void translate(int x, int y)
{
     transformMatrix.m03 -= x;
     transformMatrix.m13 -= y;
}

public void render()
{
     glBindBuffer(GL_ARRAY_BUFFER, vertid);
     glBufferData(GL_ARRAY_BUFFER, vertices, GL_DYNAMIC_DRAW);

     glEnableVertexAttribArray(0);
     glVertexAttribPointer(0, 2, GL_FLOAT, false, 2 * 4, 0);

     // Draw using glDrawArrays or glDrawElements

     glDisableVertexAttribArray(0);
}


Then you should be multiplying in your vertex shader

1  
2  
3  
4  
5  
6  
7  
8  
attribute vec2 position;

uniform mat4 transformation;

void main()
{
     gl_Position = transformation * vec4(position, 1.0, 1.0);
}


EDIT:
I should note that the transformation matrix should start as an identity with m00, m11, m22, and m33 having a value of 1.

Offline lcass
« Reply #2 - Posted 2014-04-12 20:47:31 »

Thanks for your help I will try that in a little while however, I am wandering if there is a way to still do it inside the class though. I saw at one point using glmatrixpush() worked but I didnt understand how you would get it to function.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lcass
« Reply #3 - Posted 2014-04-12 22:50:11 »

Also in your post how would I bind the transformation object you passed into the shader?
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2014-04-12 23:04:22 »

I'd advise you to learning OpenGL properly. Here's a link to a great tutorial on modern OpenGL 3.3 along with the ported Java+LWJGL code accompanying each example.

Offline lcass
« Reply #5 - Posted 2014-04-13 11:17:56 »

I'd advise you to learning OpenGL properly. Here's a link to a great tutorial on modern OpenGL 3.3 along with the ported Java+LWJGL code accompanying each example.
Thanks that has really helped.
So looking at it I would think that firstly when im using the shader I bind the object , I activate the shader variable then I point to it to assign the value , deactivate the shader variable and then render.
Offline Longarmx
« Reply #6 - Posted 2014-04-13 13:43:19 »

No. You want the shader active when you render or else it won't be used!

Offline lcass
« Reply #7 - Posted 2014-04-13 13:51:46 »

No. You want the shader active when you render or else it won't be used!
Oh no not like that I mean activate the linking the attribute then disable it then render then cancel the shader.
Offline Longarmx
« Reply #8 - Posted 2014-04-13 13:59:27 »

So you're saying
glDisableVertexAttribArray(0);
before rendering?

Offline lcass
« Reply #9 - Posted 2014-04-13 16:02:19 »

yes because once you have bound the value I thought you could stop that and leave the shader active.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #10 - Posted 2014-04-13 17:17:09 »

You have to leave those enabled or else nothing will get passed to the shader.

Offline lcass
« Reply #11 - Posted 2014-04-13 17:25:30 »

oh ok thank you
Offline lcass
« Reply #12 - Posted 2014-04-13 23:21:45 »

so basically ive setup a vertex shader

1  
2  
3  
4  
5  
6  
uniform vec2 transform;

void main()
{
   gl_Position =gl_Vertex+vec4(transform,0,0);
}


I then bind transform per VBO which is done through
int transloc =  GL20.glGetUniformLocation(shaderprogram, transform);
GL20.glUniform2f(transloc,transformationx,transformationy);

going to have to test it tommorow though. thanks for the help
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #13 - Posted 2014-04-13 23:31:52 »

Watch out, you're learning 2.0/2.1 OpenGL. gl_Vertex is deprecated in the core profile (GL 3.0+) and removed in 3.1+

Offline lcass
« Reply #14 - Posted 2014-04-13 23:37:04 »

so im required to bind it?
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #15 - Posted 2014-04-14 00:12:46 »

If you are using 2.0/2.1 or compatibility profile, then you can just keep using gl_Vertex and bind the data using glVertexPointer. If you are using core, then you create your own attributes and bind the data using glVertexAttribPointer.

If all of this is flying over your head, please do read the tutorials I linked Smiley

Offline lcass
« Reply #16 - Posted 2014-04-14 09:27:48 »

i have been and there very good tutorials. I sort of understand, however I am using the lower version shader loading and binding.
Offline lcass
« Reply #17 - Posted 2014-04-14 16:06:50 »

I am wandering what the new form of modelviewprojectionmatrix is , when I try to multiply by it in my shader I get no result. I know that the code would work with it as I tested it in the shader IDE.
Online SHC
« Reply #18 - Posted 2014-04-14 16:09:42 »

Modern OpenGL doesn't take care of the matrices for you. You have to manage your matrices on your own and send them to the shaders and multiply them there.

Offline lcass
« Reply #19 - Posted 2014-04-14 16:27:16 »

ok so which matrix would I send to the shader?
EDIT: ive fixed it I passed in a vertical scalar which is the height divided by width, then the vertex.y is divided by it inside the shader.
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.

toopeicgaming1999 (72 views)
2014-11-26 15:22:04

toopeicgaming1999 (62 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (56 views)
2014-11-12 21:11:50
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!