Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Libgdx GL20 methods  (Read 3651 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2014-05-24 06:53:59 »

So I started doing some work with libgdx opengl.

The problem I find is that the glmethods don't have same arguments. Also, some variables are poorly named and there is no doc on the web at least..

For example,
1  
Gdx.gl20.glVertexAttribPointer(indx, size, type, normalized, stride, ptr);


Why is index called indx?? That just confuses me..
What is ptr? Is it pointer to my buffer? If so, then whats the point of having a pointer there, because even though I tell the pointer to my buffer, I still get exception that I need to bind a buffer if I want to use offsets.

Is there like any doc for GL20 methods? All I can see in the doc is method names..
Offline Nate

JGO Kernel


Medals: 147
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #1 - Posted 2014-05-24 07:43:08 »

It isn't documented because it is OpenGL.
https://www.google.com/search?q=glVertexAttribPointer

Offline trollwarrior1
« Reply #2 - Posted 2014-05-24 07:51:19 »

Hmm... I think I messed something up. I thought there wasn't supposed to be a pointer value in this opengl method. Sorries.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trollwarrior1
« Reply #3 - Posted 2014-05-24 09:46:46 »

I guess this thread should be moved to debugging.

ok. Got any ideas why this doesn't display anything?

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  
public class IsoMap {

   private ShaderProgram isoShader;

   private int vertexHandle = 0;

   public IsoMap() {
   }

   public void create() {
      isoShader = new ShaderProgram(Gdx.files.internal("shaders/VertexIso.txt"), Gdx.files.internal("shaders/FragmentIso.txt"));

      createBuffers();

      float x = 100, y = 100, width = 100, height = 100;
      float z = 0;

      int size = 3 * 3;

      FloatBuffer buffer = BufferUtils.newFloatBuffer(size);
      buffer.put(x).put(y).put(z);
      buffer.put(x).put(y + height).put(z);
      buffer.put(x + width).put(y).put(z);

      buffer.flip();

      bind(vertexHandle);
      Gdx.gl20.glBufferData(GL20.GL_ARRAY_BUFFER, size, buffer, GL20.GL_STATIC_DRAW);
      bind(0);

      String log = isoShader.getLog();
      if (log.length() > 0) System.out.println(log);
   }

   private void createBuffers() {
      IntBuffer intBuffer = BufferUtils.newIntBuffer(1);
      Gdx.gl20.glGenBuffers(1, intBuffer);
      vertexHandle = intBuffer.get(0);
   }

   public void draw() {
      isoShader.begin();

      Matrix4 projectionMatrix = new Matrix4().setToOrtho(Gdx.graphics.getWidth(), 0, Gdx.graphics.getHeight(), 0, -1, 1);
      isoShader.setUniformMatrix(isoShader.getUniformLocation("u_projTrans"), projectionMatrix, false);

      isoShader.enableVertexAttribute("a_position");

      bind(vertexHandle);
      Gdx.gl20.glVertexAttribPointer(isoShader.getAttributeLocation("a_position"), 3, GL20.GL_FLOAT, false, 0, 0);
      bind(0);

      Gdx.gl20.glDrawArrays(GL20.GL_TRIANGLES, 0, 3);

      isoShader.disableVertexAttribute("a_position");

      isoShader.end();
   }

   private static final void bind(int buffer) {
      Gdx.gl20.glBindBuffer(GL20.GL_ARRAY_BUFFER, buffer);
   }
}


1  
2  
3  
4  
5  
6  
7  
attribute vec3 a_position;

uniform mat4 u_projTrans;

void main() {
   gl_Position = vec4(a_position, 1) * u_projTrans;
}


1  
2  
3  
4  
5  
6  
7  
#ifdef GL_ES
precision mediump float;
#endif

void main() {
    gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}
Offline trollwarrior1
« Reply #4 - Posted 2014-05-24 09:58:12 »

Okay I fixed it. Had to change to this:
1  
2  
Matrix4 projectionMatrix = new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), 0, Gdx.graphics.getHeight(), -1, 1);
isoShader.setUniformMatrix(isoShader.getUniformLocation("u_projTrans"), projectionMatrix, true);


at line 44 or something
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (75 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (28 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (35 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
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!