Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 Views  (Read 2049 times)
0 Members and 1 Guest are viewing this topic.
Offline MickeyB

Senior Devvie




my game will work, my game will work!


« Posted 2004-05-13 16:49:27 »

LWJGL - Looking for some clarification and what nots.  If I want to do a 2d game, with no 3d at all, then I could use the game loop in another thread here and use the default ortho 1:1 view, draw on screen with 0,0 in the lower left corner?  and leave all z's at 0?

If I want any 3d in it, then I need to go ortho box deeper than 1 (like AlienFlux below)

1  
2  
3  
4  
5  
6  
7  
// Go into orthographic projection mode
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluOrtho2D(0, WIDTH, 0, HEIGHT);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
            GL11.glViewport(0, 0, width, height);


or gluPerspective (fovy, aspect, near, far) or something similar?

M

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2004-05-13 17:23:47 »

Quote
LWJGL - Looking for some clarification and what nots.  If I want to do a 2d game, with no 3d at all, then I could use the game loop in another thread here and use the default ortho 1:1 view, draw on screen with 0,0 in the lower left corner?  and leave all z's at 0?

Yup.

Quote
If I want any 3d in it, then I need to go ortho box deeper than 1 (like AlienFlux below)

gluOrtho2D will give you a depth range of -1 to 1 (although you could also use glOrtho and specify near and far yourself). However it'll still give you a parallel projection - you won't get any foreshortening of objects in the distance. If you want the perspective shortening you use glPerspective as you mentioned.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline MickeyB

Senior Devvie




my game will work, my game will work!


« Reply #2 - Posted 2004-05-13 18:35:18 »

great...thanks!  lovin it!

So if I have a starship with a planet in the distance, use glPerspective?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 433
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2004-05-14 06:36:24 »

Well, there's 2 ways of doing it: either actually use Z coodinates to make things appear smaller, using perspective, or just draw the planet first and much smaller.

Cas Smiley

Offline MickeyB

Senior Devvie




my game will work, my game will work!


« Reply #4 - Posted 2004-05-14 10:53:03 »

Great, thanks!!  Off to some 2d and 3d game dev with LWJGL.......after spending some time with the redbook.  Grin

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline MickeyB

Senior Devvie




my game will work, my game will work!


« Reply #5 - Posted 2004-05-20 19:52:58 »

an assumption...

to do an overhead scroller with LWJGL, I need to keep my "veiwpoint/camera" in in the same position as my centerd object just higher up and no rotating (think Subspace)  correct?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline princec

« JGO Spiffy Duke »


Medals: 433
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2004-05-20 20:59:49 »

More or less. Just translate the x and y coordinates to your ship's coordinates and you'll find that it appears in the middle of the screen. Try it and see.

Cas Smiley

Offline MickeyB

Senior Devvie




my game will work, my game will work!


« Reply #7 - Posted 2004-05-21 14:22:31 »

Thanks, I'll give a try!  My problem is learning how do do and move the veiwpoint.  I have your basic loop with the default 1:1 orhte2d set up from Window.create(string), and a glu.gluPerspective(....) for a 3d view.

Need to figure out how to move the viewpoint.... :-/

Love the performance I am getting with what I see so far!

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #8 - Posted 2004-05-21 14:55:38 »

Unlike DirectX, OpenGL doesn't have separate camera and object matrices, the modelview matrix takes the place of both of them. So typically you do something like:

glMatrixMode( PROJECTION );
glOrtho( ... ); // Setup projection

glMatrixMode( MODELVIEW );
glTranslatef( inverse of camera position ); // 'moves' the view so it looks at the camera position

// For each object..
glPushMatrix();
glTranslatef / glRotatef // Set position/rotation of current object
// draw object
// ..

glPopMatrix(); // Pop off current transforms and return to just camera transform.

Although for a 2d game you probably don't want the overhead of push, translate, pop, for every sprite. So just calculate this manually.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline MickeyB

Senior Devvie




my game will work, my game will work!


« Reply #9 - Posted 2004-05-21 17:57:35 »

ok, I did this, using the base game loop...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
    int x = 5;
    int y = Window.getHeight() - height - 50;
    int z = 20;
   
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glTranslatef(0.4f, 0.0f, 0.0f);  // positive y goes up, positive x goes right, any change to z takes it out or 1:1 2d view
    GL11.glPushMatrix();
   
        GL11.glBegin(GL11.GL_LINE_STRIP);
        {
          GL11.glColor3f(0.0f, 0.9f, 0.0f);
          GL11.glVertex2i(x - 1, y);
          GL11.glVertex2i(x + width, y);
          GL11.glVertex2i(x + width, y + height + 1);
          GL11.glVertex2i(x - 1, y + height + 1);
          GL11.glVertex2i(x - 1, y);
          System.out.println("x: " + x);

        }
        GL11.glEnd();
        GL11.glPopMatrix();


When I run this, my green line array that makes a rectangle moves to the right....which means my viewpoint is moving to the left and x is always 5 because I am not moving the box, just my viewpoint.  Now to take Cas' suggestion and send my viewpoint x and y to my centered avatar, it will sit in the "center" where my camera is looking.  Its x and y will be my "camera" x and y.....

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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