Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  jogl 2d newbie  (Read 3205 times)
0 Members and 1 Guest are viewing this topic.
Offline tortoise

Junior Member




<3 Shmups


« Posted 2003-07-10 11:47:42 »

Hi, I'm very new to gl and jogl (and debated posting this here or newless cluebies). I want to use jogl for my 2D game so it will run well on more than just Windows. But in my research I've come up with some questions...

I'm a little stumped as to where the GL class resides? I have downloaded the jogl source out of cvs. There's no GL.java in jogl, and searching for things like "class GL" or "interface GL" turns up nothing. I assume all gl* functions from the standard C implementation of openGL would be found in the GL class? Searching for things like glBegin show a lot of other classes using the method, but not where it's originating from.

What about glDrawPixels, glBitmap, etc? I also was unable to find those as well. I am curious how much of the 2D side of openGl is implemented, or if I'm even on the right track at all.

In doing some small toy programs with jogl, I can't get the color to change no matter what I do. For example I stripped the Gears demo down and replaced drawing the gears with just drawing a few polys, I have something like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public void display(GLDrawable drawable)
{
       // glClearColor set to black
     gl.glclear( GL.GL_COLOR_BUFFER_BIT );
     
      gl.glColor3f( 0.0f, 1.0f, 0.0f );
      gl.glBegin( GL.GL_POLYGON );
          gl.glVertex2f( 0.0f, 0.0f );
          gl.glVertex2f( 1.0f, 0.0f );
          gl.glVertex2f( 0.0f, 1.0f );
      gl.glEnd();
      gl.glFlush();
}


but no matter what the triangle is always a dark red. Weird that's dark red, I'd think if anything it'd be (1.0, 0.0, 0.0) red, I've experimented with specifying the color at other times and such with no luck.

My game currently has a render class that all sprites register themselves with. When it comes time to draw the frame the renderer's Graphic object is passed around to everyone and they all do their thing. Is this a feasable approach with jogl? Obviously not a Graphics object, but perhaps a small inner class of my renderer that accepts an image and coordinates and draws it to the GLCanvas with I assume glDrawPixels or something like it?

I'm also curious on the whole pasting sprites onto polygons as textures vs just blitting the sprites as is. In searching (not just these forums but the internet for openGL stuff in general) I've found it split about 50/50. It seems that generally the more game oriented people seem to prefer the polygon/texture route. Should that be the way I head? I have a feeling that'd drastically change my game's structure.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #1 - Posted 2003-07-10 16:13:10 »

I think the source to that class is generated by the build process from the openGL C header files.  That's what all the fuss is about with respect to GlueGen and antlr

Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #2 - Posted 2003-07-10 17:04:08 »

Yep.. it is automagically created by GLEmitter.java.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Archimedes
Guest
« Reply #3 - Posted 2003-07-10 17:36:06 »

Quote

Instead of compiling Jogl for yourself, you can also download the binary archive for the current supported platforms from http://jogl.dev.java.net/servlets/ProjectDocumentList

Quote
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public void display(GLDrawable drawable)
{
 // glClearColor set to black
gl.glclear( GL.GL_COLOR_BUFFER_BIT );

gl.glColor3f( 0.0f, 1.0f, 0.0f );
gl.glBegin( GL.GL_POLYGON );
    gl.glVertex2f( 0.0f, 0.0f );
    gl.glVertex2f( 1.0f, 0.0f );
    gl.glVertex2f( 0.0f, 1.0f );
gl.glEnd();
gl.glFlush();
}

The flush()-command isn't necessary AFAIK. According to the user's manual http://jogl.dev.java.net/unbranded-source/browse/*checkout*/jogl/doc/userguide/index.html it's advisable to set the gl and glu variables every time in the reshape and display event-handler methods.
1  
2  
GL  gl  = drawable.getGL();
GLU glu = drawable.getGLU();

But this shouldn't be the problem at your side, where the triangle is dark red. :)

Well, I've to set the camera back a bit in order to see your triangle. So between your clClear and the glColor I've to do:
1  
2  
o.glLoadIdentity();
o.glTranslated(0, 0, -10);

Then the triangle is green, as you specified it.
Still, this doesn't explain why you're triangle is dark red. :-)  Do you issue some exotic commands in the initial init() method of your render class?

Quote
My game currently has a render class that all sprites register themselves with. When it comes time to draw the frame the renderer's Graphic object is passed around to everyone and they all do their thing. Is this a feasable approach with jogl? Obviously not a Graphics object, but perhaps a small inner class of my renderer that accepts an image and coordinates and draws it to the GLCanvas with I assume glDrawPixels or something like it?

I'm not sure if I understood you correctly, but in OpenGL - and also Jogl - all drawing happens in the display-method of your render class which implements GLEventListener. There you can of course fetch all your registered sprite classes and call their render method (with parameters "GL gl" and "GLU glu") which then just issue the appropriate glCommands.
Or did you mean it that way?

Quote
I'm also curious on the whole pasting sprites onto polygons as textures vs just blitting the sprites as is. In searching (not just these forums but the internet for openGL stuff in general) I've found it split about 50/50. It seems that generally the more game oriented people seem to prefer the polygon/texture route. Should that be the way I head? I have a feeling that'd drastically change my game's structure.

Unfortunately I can't judge this from experience. However I read that today's 3d cards are really optimized for texture polygons so they're not slower than glDrawpixel, probable even faster - especially when you glBindTexture so that the texture bitmaps resides on the graphics card's fast V-RAM.
Further I'd use the textured polygon way because in case you want to change the camera during the game - and if it's just to zoom in and out, or rotate around the z axis (or any other) from time to time. So it could look as cool as the funny Spactripper game does ( http://www.pompom.org.uk/ )

:-)
Offline Caoimhin

Junior Member





« Reply #4 - Posted 2003-07-10 22:44:43 »

Regarding your colors, are you doing flat shading instead of smooth shading?

The code below draws a tri-colored triangle and a single solid colored square.

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  
public void display(GLDrawable gLDrawable)
{
  final GL gl = gLDrawable.getGL();
  gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  gl.glLoadIdentity();
  gl.glTranslatef(-1.5f, 0.0f, -6.0f);
  gl.glBegin(GL.GL_TRIANGLES);                                    // Drawing Using Triangles
   gl.glColor3f(1.0f, 0.0f, 0.0f);
    gl.glVertex3f( 0.0f, 1.0f, 0.0f);            // Top
   gl.glColor3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f,-1.0f, 0.0f);            // Bottom Left
   gl.glColor3f(0.0f, 0.0f, 1.0f);
    gl.glVertex3f( 1.0f,-1.0f, 0.0f);            // Bottom Right
 gl.glEnd();                                          // Finished Drawing The Triangle
 gl.glTranslatef(3.0f, 0.0f, 0.0f);
  gl.glBegin(GL.GL_QUADS);              // Draw A Quad
   gl.glVertex3f(-1.0f, 1.0f, 0.0f);            // Top Left
   gl.glVertex3f( 1.0f, 1.0f, 0.0f);            // Top Right
   gl.glVertex3f( 1.0f,-1.0f, 0.0f);            // Bottom Right
   gl.glVertex3f(-1.0f,-1.0f, 0.0f);            // Bottom Left
 gl.glEnd();                                          // Done Drawing The Quad
 gl.glFlush();
}

public void init(GLDrawable gLDrawable)
{
  final GL gl = gLDrawable.getGL();
  gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  gl.glShadeModel(GL.GL_SMOOTH);
}
Offline tortoise

Junior Member




<3 Shmups


« Reply #5 - Posted 2003-07-10 23:09:36 »

Turns out the color thing was a driver problem. All JOGL apps drew in a dark red on both my laptop (win2k) and desktop (winXP). No matter what I did or what app it was. The gears demo had dark red gears and an example I ported out of the OpenGL red book verbatim was all red too. I should run some standard C OpenGL code and see what it does.

I then installed the nvidia drivers and everything's ok now. I guess the OpenGL dll's that ship with Windows aren't very good. I just hope my dinkey laptop video card has some drivers I can install.

I originally wanted to look at the GL class to see if there are any differences I should watch out for, but so far it's dead on, so I'll stop worrying about it.

I read up more on textures vs bitmaps and it seems textures are better, but I'll drop that as it's not really a JOGL thing.

Thanks for all the help guys. Both OpenGL and JOGL have turned out to be quite nice so far.
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #6 - Posted 2003-07-13 22:44:11 »

Quote
It seems that generally the more game oriented people seem to prefer the polygon/texture route. Should that be the way I head?


I expect most here would concur with that statement.  Graphics cards these days are designed primarily to draw textured triangles very, very fast.  And they're getting faster!  That consideration alone should sway you. Wink

Hellomynameis Charlie Dobbie.
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #7 - Posted 2003-07-14 01:10:06 »

Textures by far are the best way to go - they fit right into the optimal OpenGL pipeline and should always yield the best performance.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
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.

TehJavaDev (13 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (32 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (19 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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!