Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  LWJGL Graphics Flow Question  (Read 587 times)
0 Members and 2 Guests are viewing this topic.
Offline StumpyStrust

Full Member
**

Posts: 103
Medals: 1



« on: 2011-12-31 02:55:36 »

So I want to start doing stuff with OpenGL using LWJGL.

I understand the basic way of setting up a window, openGL, rendering loop.

But in all the tutorials I have read, not one shows how to render with OpenGL outside of a class. Its all hard coded.


The flow in java using the Graphics object basically goes

tell objects to draw themselves by passing them the Graphics object from your draw method.

Example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void drawSelf( Graphics g )
   {
      if(alive)
      {
         double x1 = (int)size >> 1;
                        double y1 = (int)size >> 1;
                        Graphics2D g2d = (Graphics2D)g.create();
         Composite alphaComp = AlphaComposite.getInstance(
                               AlphaComposite.SRC_OVER, (float) fade);
         g2d.setComposite(alphaComp);
         g2d.drawImage(texture, (int)(loc.x - x1), (int)(loc.y - y1), (int)size, (int)size, null);
         g2d.dispose();
      }
   }


So what is the flow for OpenGl? I know how to hardcode something in it like this

Example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
while (!Display.isCloseRequested()) 
        {
 
           GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);  
           
           GL11.glColor3f(0.2f,0.1f,1.0f);
           
           GL11.glBegin(GL11.GL_QUADS);
              GL11.glVertex2f(100,100);
              GL11.glVertex2f(100+200,100);
              GL11.glVertex2f(100+200,100+200);
              GL11.glVertex2f(100,100+200);
           GL11.glEnd();
 
           Display.update();
      }


But how would you draw say a list of square objects?

Can you not pass them the resources they need to draw themselves?

Do you have to get their drawing information and then use that to drraw them?

I am lost and any help would be fantastic.
Online ra4king

JGO Kernel
*****

Posts: 3158
Medals: 196


I'm the King!


« Reply #1 on: 2011-12-31 04:07:27 »

Since all LWJGL methods are static, there is no Graphics2D object to pass around. So you can still have the standard game loop (update() -> render() -> sleep() and restart) and each of your Entities's render methods would basically just call OpenGL functions. Think of GLXX as your Graphics2D class except all the methods you can use are static.

Offline StumpyStrust

Full Member
**

Posts: 103
Medals: 1



« Reply #2 on: 2011-12-31 05:43:35 »

Well that makes things seem really simple.
 
Although I have a feeling that doing it that way is going to byte me in the ass.  Cheesy

I don't know how but it will.
Games published by our own members! Go get 'em!
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #3 on: 2011-12-31 05:49:56 »

The OpenGL methods can be static (partly) because they can only be accessed from a single thread: the thread that owns the OpenGL context. It's also only possible to draw to a single "image" at a time, so having multiple GL objects would not make much sense.

Just because you can call the static OpenGL methods from any class doesn't mean that you SHOULD call them from any class. Try to keep everything as clean as possible. =)

There is no god.
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #4 on: 2011-12-31 08:31:47 »

Although I have a feeling that doing it that way is going to byte me in the ass.  Cheesy
it will, when you become overjoyed and forget which class should drawing and not.

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.088 seconds with 19 queries.