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   
Pages: [1]
  ignore  |  Print  
  LibGDX 3D GL20 Wireframe  (Read 1276 times)
0 Members and 1 Guest are viewing this topic.
Offline KudoDEV

Senior Newbie





« Posted 2013-10-09 19:55:53 »

How do i render mesh wireframe in GL20 in GL10 you use glPolygonMode(GL20.GL_FRONT_AND_BACK, GL20..GL_LINE);

however, glPolygonMode doesn't exist in GL20
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-10-09 20:08:17 »

Just because it's not in GL20 doesn't mean it's not supported in OpenGL 2.0

GL11.glDrawArrays() is still used even in the most recent versions of OpenGL.

Offline KudoDEV

Senior Newbie





« Reply #2 - Posted 2013-10-09 20:24:45 »

Is glDrawArrays efficient? More than mesh.render?

If so that would make some things a lot better for me.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #3 - Posted 2013-10-09 20:26:03 »

I don't know what mesh.render() is, but I suspect it uses glDrawArrays() or glDrawElements() underneath anyway.

Offline KudoDEV

Senior Newbie





« Reply #4 - Posted 2013-10-09 20:31:08 »

Thanks that was helpful. So to answer a question that I had before that was never answered.

Can I use glDrawArrys and bind textures to make it a tile based 3D terrain?
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #5 - Posted 2013-10-09 20:49:03 »

I think you might be missing the point of glDrawArrays()

glDrawArrays is part of low-level OpenGL. It does exactly what it says. It draws arrays of data (VAs, VBOS, VAOs). Texture binding is done before calling glDrawArrays, and is separate from glDrawArrays().

'mesh' I assume is part of LibGDX, and is a higher-level abstraction of the normal process for drawing arrays in OpenGL.

You should probably check the LibGDX documentation/wiki before you start mixing low-level and high-level functions in order to avoid conflicting code (calling a low-level function that was already called within a high-level function and vice-versa).

To simply answer your question: Yes, glDrawArrays can be used to draw textured tiles-based 3D terrain, amongst many other things.

Offline KudoDEV

Senior Newbie





« Reply #6 - Posted 2013-10-09 20:57:35 »

Yes I know the difference. And I just took a look at mesh.java in the github.

I don't see how it draws the vertex arrays since none of the args are vertexes, I think I'm missing something.


can I get an example of how to use glDrawArrays?


this is what mesh.java looks like

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  
public void render (ShaderProgram shader, int primitiveType, int offset, int count, boolean autoBind) {
      if (!Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 1.x");
      if (count == 0) return;

      if (autoBind) bind(shader);

      if (isVertexArray) {
         if (indices.getNumIndices() > 0) {
            ShortBuffer buffer = indices.getBuffer();
            int oldPosition = buffer.position();
            int oldLimit = buffer.limit();
            buffer.position(offset);
            buffer.limit(offset + count);
            Gdx.gl20.glDrawElements(primitiveType, count, GL10.GL_UNSIGNED_SHORT, buffer);
            buffer.position(oldPosition);
            buffer.limit(oldLimit);
         } else {
            Gdx.gl20.glDrawArrays(primitiveType, offset, count);
         }
      } else {
         if (indices.getNumIndices() > 0)
            Gdx.gl20.glDrawElements(primitiveType, count, GL10.GL_UNSIGNED_SHORT, offset * 2);
         else
            Gdx.gl20.glDrawArrays(primitiveType, offset, count);
      }

      if (autoBind) unbind(shader);
   }
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #7 - Posted 2013-10-09 21:12:54 »

None of the args are vertices because they must be bound before calling glDrawArrays().

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
// The VBO is set up like this:
// VTCVTCVTC... etc. where V is vertex data (x, y), T is texcoord data (u, v) and C is colour data (r, g, b, a)

glBindBuffer(GL_ARRAY_BUFFER, buffer); // Bind the VBO

glVertexPointer(2, GL_FLOAT, 32, 0); // Tell OpenGL where to find the vertex data.
glTexCoordPointer(2, GL_FLOAT, 32, 8L); // Tell OpenGL where to find the texture coordinate data.
glColorPointer(4, GL_FLOAT, 32, 16L); // Tell OpenGL where to find the color data.

glDrawArrays(GL_TRIANGLES, 0, vc); // Draw the data

glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the VBO


Please note that this uses some deprecated code (gl___Pointer). This code is for pre-OpenGL 2.0. After OpenGL 2.0, you should be using shaders and glVertexAttribPointer() instead.

This is just meant to be an example. It is a bad example, but shows how glDrawArrays() gets its data.

Offline davedes
« Reply #8 - Posted 2013-10-10 01:47:57 »

glPolygonMode doesn't exist in LibGDX since it's not part of OpenGL ES. If you want that function, you'd have to expose it yourself through LWJGL or whatever backend you choose.

You can just render the triangles with GL_LINES if you want something simple. In other instances it might be better to use barycentric coordinates, discussed here:
http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/

Also note, it will be much easier to use the Mesh and VertexAttribute utilities instead of dealing with VBOs and calling glDrawArrays/etc directly. It is more robust and should also deal with any platform quirks that might crop up. See here:
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Meshes

Easier still is to use the 3D API for rendering meshes:
http://blog.xoppa.com/

Offline KudoDEV

Senior Newbie





« Reply #9 - Posted 2013-10-10 04:20:42 »

I've been toying with meshes and shaders to make tile based terrain textures. However, I cannot figure out how to draw textures between certain vertices.

I've even though about using decals, but I held back because that would be sloppy.

I've been at it for days.
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.

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