Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 1093 times)
0 Members and 1 Guest are viewing this topic.
Offline javatypo

Junior Duke





« Posted 2003-12-26 18: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 Duke





« Reply #1 - Posted 2003-12-26 19: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 Duke





« Reply #2 - Posted 2003-12-26 21: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 22: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 Duke





« Reply #4 - Posted 2003-12-27 13: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.

Longarmx (45 views)
2014-10-17 03:59:02

Norakomi (35 views)
2014-10-16 15:22:06

Norakomi (27 views)
2014-10-16 15:20:20

lcass (31 views)
2014-10-15 16:18:58

TehJavaDev (61 views)
2014-10-14 00:39:48

TehJavaDev (61 views)
2014-10-14 00:35:47

TehJavaDev (51 views)
2014-10-14 00:32:37

BurntPizza (67 views)
2014-10-11 23:24:42

BurntPizza (39 views)
2014-10-11 23:10:45

BurntPizza (81 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!