Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  why does this look like a rectangle?  (Read 1040 times)
0 Members and 1 Guest are viewing this topic.
Offline javatypo

Junior Member





« Posted 2003-12-26 19:42:38 »

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  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
import org.lwjgl.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;

public class Game {
      //variables
     static boolean finished = false;
     
      // set up the window
     static {
            try {
                  Window.create("HELLO WORLD",50,50,640,480,32,0,8,0); // create a window
           } catch (Exception e) { e.printStackTrace(); System.exit(0); }
      }
     
      public static void main(String argv[]) {
            try {
                  {
                        Keyboard.create(); // create the keyboard, must be after creation of the window, so keyboard can focus on the window
                       GL.glClearColor(0.0f,0.0f,0.0f,0.0f); // set clearing color,
                       GL.glMatrixMode(GL.GL_PROJECTION); // init viewing values
                       GL.glLoadIdentity(); // reset matrix
                       GL.glOrtho(0.0f,1.0f,0.0f,1.0f,0.0f,0.0f); // coordinate system
                 }
           
                  while (!finished) {
                        render(); // and check for events
                       Window.update(); // update window state in order to handle close requests, moves and paints
                       Window.paint(); // paints the window, swaps buffers
               }
                Window.destroy();
                Keyboard.destroy();
          }
          catch (Exception exp) { exp.printStackTrace(); }
      }
     
      public static void render() {
            // handled events
           if (Window.isCloseRequested()) { // is the close button clicked
                 finished = true; // if yes break out of the rendering loop and exit
                 return;
            }
            Keyboard.poll(); // poll keyboard
           if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // is escape key pressed
                 finished = true; // if yes break out of the rendering loop and exit
                 return;
            }
           
            GL.glClear(GL.GL_COLOR_BUFFER_BIT); // clear the screen (color buffer)
           GL.glColor3f(0.0f,1.0f,0.0f); // color that the square will be
           GL.glBegin(GL.GL_POLYGON); // begin the square
           {
                  GL.glVertex3f(0.25f,0.25f,0.0f); // pt 1
                 GL.glVertex3f(0.75f,0.25f,0.0f); // pt 2
                 GL.glVertex3f(0.75f,0.75f,0.0f); // pt 3
                 GL.glVertex3f(0.25f,0.75f,0.0f); // pt 4
           }
            GL.glEnd(); // end the square
     }
}


this is my first lwjgl prog.. i understand mostly how everything there works, which is why all it does it make a square. but when i run the program it looks like a rectangle? why is that?

thanks.
Offline elias

Senior Member





« Reply #1 - Posted 2003-12-26 20:43:22 »

Try to give your square a little breathing room in the Z dimension. You need to replace

GL.glOrtho(0.0f,1.0f,0.0f,1.0f,0.0f,0.0f);

with something like
GL.glOrtho(0.0f,1.0f,0.0f,1.0f,-10.0f,10.0f);

If it helps, your clipping planes had cut your square into a rectangle.

- elias

Offline javatypo

Junior Member





« Reply #2 - Posted 2003-12-26 22:22:03 »

ok il try the ortho thing..

whats a clipping pane? ( i know what it is.. but not lwjgl wise)

how do i adjust that?

thanks.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2003-12-26 23:47:30 »

The coordinates used in the polygon drawing is relative the frustum specified by glOrtho. Which again is relative to the screen size itself.

So in short, (0.25, 0, 0.75) becomes (0.25*640, 0, 0.75*480). If you wan't it to be square you should make ortho match the aspect ratio of the screen. I suggest: "GL.glOrtho(0.0f,640.0f, 0.0f,480.0f,-10.0f,10.0f);". This way you can specifie the coordinates in screen space.

Offline javatypo

Junior Member





« Reply #4 - Posted 2003-12-27 14:29:35 »

hi

ic what u mean. i thought it might have something to do with how the screen was setup, because i changed those values and the shape changed.

thank you for that explanation Cheesy
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.

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

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

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

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
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

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!