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  
  LWJGL Graphics Flow Question  (Read 1281 times)
0 Members and 1 Guest are viewing this topic.
Offline StumpyStrust
« Posted 2011-12-31 08: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.

Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-12-31 10: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
« Reply #2 - Posted 2011-12-31 11: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2011-12-31 11: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. =)

Myomyomyo.
Offline ReBirth
« Reply #4 - Posted 2011-12-31 14: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]
  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 (25 views)
2014-07-29 18:09:19

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

Dwinin (13 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 (44 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!