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]
  ignore  |  Print  
  [LibGDX] Calling LWJGL/OpenGL glBegin  (Read 1380 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-08-14 16:37:26 »

I am trying to render in GL_TRANGLE_FANS for one of my projects, but my problem is I can't seem to call OpenGL's glBegin(int) using Gdx.gl or any others (gl10, 20, 11, common).

Apparently you can use Meshes, however with the way I need to do things I need to use OpenGL's state base rendering (glBegin(GL_whatever_shape);//choose vertex3f's;glEnd()Wink.

What do you guys think?

Thanks,
-cMp

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline Redocdam

Senior Member


Medals: 17



« Reply #1 - Posted 2013-08-14 17:24:15 »

I can't speak to using LibGDX, but the OpenGL functions you are trying to call are part of the fixed pipeline and are deprecated. Maybe LibGDX only exposes relevant functionality based on the OpenGL version you're working in?

Aside from that, I would like to steer you away from the deprecated functions. For every function which has been placed on the endangered species list, there now exists a newer and better way of accomplishing the same goal. I'm curious why you need to use the older methodology.
Offline Slyth2727
« Reply #2 - Posted 2013-08-14 17:26:23 »

Wow really, those are deprecated? What are the new functions?

I was interested in using those functions because I was trying to draw a 2d light source with this code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
gl.glBegin(GL.GL_TRIANGLE_FAN);
  {
    gl.glColor4f(0f, 0f, 0f,  intensity);
    gl.glVertex3f(center.x, center.y, depth);
     
    gl.glColor4f(0f, 0f, 0f, 0f);
     
    for (float angle=0; angle<=Math.PI*2; angle+=((Math.PI*2)/numSubdivisions) )
    {
      gl.glVertex3f( radius*(float)Math.cos(angle) + center.x,
                     radius*(float)Math.sin(angle) + center.y, depth);  
    }
     
    gl.glVertex3f(center.x+radius, center.y, depth);
  }
    gl.glEnd();

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Simba Productions

Senior Newbie


Medals: 1



« Reply #3 - Posted 2013-08-14 18:11:19 »

make sure your alpha blend in enabled and i would assume you would want to use 1f, 1f, 1f for your rgb's since 0f, 0f, 0f is black.
 
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
         Gl11.glEnable(GL11.GL_BLEND);
         GL11.glBegin(GL11.GL_TRIANGLE_FAN);
           {
           
             GL11.glColor4f(1f, 1f, 1f,  intensity);
             GL11.glVertex3f(center.x,center.y, 0f);
               
             GL11.glColor4f(1f, 1f, 1f, 0f);
               
             for (float angle=0; angle<=Math.PI*2; angle+=((Math.PI*2)/subdivisions) )
             {
               GL11.glVertex3f( radius *(float)Math.cos(angle)+ center.x,
                              radius * (float)Math.sin(angle)+ center.y, 0);  
             }
               
             GL11.glVertex3f(radius + center.x, center.y, 0);
           }
             GL11.glEnd();


keep in mind that this method of rendering has been deprecated for a long time. with lower subdivisions it will look a little weird that's because the alpha is blended for each triangle separately making the fact that there are many different triangles apparent

edit: Just realized your talking about using LWJGL through LibGDX. dunno how you would do this in LibGDX this is just the straight LWJGL way to do it. If it exists in LibGDX i would assume it would be very similar to the above code though
Offline davedes
« Reply #4 - Posted 2013-08-14 19:24:21 »

Where are you getting that code? Immediate mode was deprecated years ago; and is not supported by OpenGL ES.

The modern programmable pipeline is quite a bit more complicated -- you need to set up shaders, VBOs, and all that jazz.

Fortunately, LibGDX includes a lot of utilities that make it easy to work in the programmable pipeline. For example, the ImmediateModeRenderer, which mimics the immediate mode you're using there.

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  
ImmediateModeRenderer r;

... create()
   if (Gdx.graphics.isGL20Available()) {
       //normals=false, colors=true, numTexCoords=none
      r = new ImmediateModeRenderer20(false, true, 0);
   } else {
       r = new ImmediateModeRenderer10();
   }


... render()
   //enable srcOver blending
  Gdx.gl.glEnable(GL10.GL_BLEND);
   Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

   //for example, this can use your OrthographicCamera
  r.begin(camera.combined, GL20.GL_TRIANGLE_FAN);

   ...

   //push our vertex data here...

   //.. similar to glColor4f
  r.color(0f, 0f, 0f, intensity);
   
   //.. similar to glVerte3f
  r.vertex(center.x, center.y, depth);
   
   ...

   //flush the renderer
  r.end();

   
Ideally, if you plan to render many of these lights, it would be best to use GL_TRIANGLES and batch them into a single render call.

For more in-depth information on meshes:
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Meshes

Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #5 - Posted 2013-08-14 19:29:36 »

Wow really, those are deprecated? What are the new functions?

I was interested in using those functions because I was trying to draw a 2d light source with this code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
gl.glBegin(GL.GL_TRIANGLE_FAN);
  {
    gl.glColor4f(0f, 0f, 0f,  intensity);
    gl.glVertex3f(center.x, center.y, depth);
     
    gl.glColor4f(0f, 0f, 0f, 0f);
     
    for (float angle=0; angle<=Math.PI*2; angle+=((Math.PI*2)/numSubdivisions) )
    {
      gl.glVertex3f( radius*(float)Math.cos(angle) + center.x,
                     radius*(float)Math.sin(angle) + center.y, depth);  
    }
     
    gl.glVertex3f(center.x+radius, center.y, depth);
  }
    gl.glEnd();


All glBegin .. glEnd and loads of other functions are depricated.
Replacements are vbo's and shaders.
Offline Redocdam

Senior Member


Medals: 17



« Reply #6 - Posted 2013-08-14 21:47:12 »

As RobinB said, you'll want to use Vertex Array Objects, Vertex Buffer Objects and Shaders. These are the meat and potatoes of the new OpenGL pipeline. The process involves stuffing a bunch of information like Vertices into a buffer and then a script (called a shader) processes the data for rasterization. As DaveDes said, LibGDX has some utilities to make your life easier. It's also going to require using matrices to position your objects in the 3D world. Again, LibGDX likely has a lot of that hard work done for you.
But don't let all those long words scare you away. Just take it piece by piece and you'll find it's really not that bad. A little more work than the fixed pipeline, but easily doable.

Billboarding
This is likely getting a bit ahead of you, since you'll want to get the basics of working VAOs, VBOs and Shaders down first. So this is for after you go down that dark road.

It looks like you're putting together some billboards. This is the process of taking a flat panel and making it always face the camera. You can think of billboarding like a sign on the side of the road, only these signs would always face you no matter where you stand. Typically this is done with a quad and a transparent image instead of a disc. Rendering a quad is a lot faster, since it's only 4 vertices. Though it's not limited to just quads, so if you really want to use a disc, then you can still use the methods I'm going to list, to help tackle your problem.

Easy Method
Just don't billboard. Stuff a sphere into a VAO/VBO and render it where you need. I bring this up, because if you just want something to represent where your light is for development purposes, there's no reason to go mad over billboards just yet. If you want to use this in actual game play, then it's probably not the best method. Especially if you'd be using a lot of them, then you would need to use instanced rendering and blah blah... so no.

Medium Method
Stuff a quad into a VAO/VBO. Pretty simple so far.
The next part is a little more tricky and requires using something called a "Look At" matrix. This does what the name implies. You feed it 3D vectors called Eye, At and Up. The matrix then does some behind the scenes magic and makes the object face where you want it to. This is perfect for billboards, just tell it to look at the camera and shazam instant billboard.

The previously mentioned vectors are
Eye: The location of the object.
At: A point the object is looking at
Up: Which direction the top of the object is facing (sort of).

Note: sometimes people refer to these vectors in different names like "right, center and up". I imagine LibGDX has already implemented the math for this and you just need to figure out the syntax for calling it.

Difficult Method
My favorite method for handling billboards expands on the previous example. Though instead of flipping back and forth between the CPU and GPU, we simply feed a bunch of 3D vectors to the GPU and then use something called a Geomtry shader to create the actual billboards.
What makes this somewhat difficult is you'll first need to learn how to use Geometry shaders. Then you'll need to figure out how to calculate the Eye, At and Up vectors in the shader. So you'll need to know a bit of basic vector math.
It's not terribly complicated, it just requires a lot of basic knowledge about a bunch of different things.

The really nice part about this is being able to deal with billboards as single points, which becomes very useful when you get into particles systems. It also leaves the door open for some advanced particle systems which exist solely on the GPU (which means stupid fast).

You'll probably want to work your way up to this though. I mention this mostly as something to keep in mind, so you don't get too entrenched in a more basic method.
Offline Slyth2727
« Reply #7 - Posted 2013-08-15 04:47:59 »

Thanks for the reply Redocdam, I can tell you put work into it Smiley. I am just trying to do 2d geometry shadow mapping though, but this information is enormously helpful! I will go on and face the world of OpenGL!!!!! Thou hast strengthened me!

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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.

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

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

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

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

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

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

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
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

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!