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  
  Drawing a Quad  (Read 1224 times)
0 Members and 1 Guest are viewing this topic.
Offline nech_neb

Junior Duke




Java for LIFE !!!


« Posted 2004-07-25 08:02:22 »

Suppose I want to draw a quad on the screen using
LWJGL.

Form pixel locaion (200,200) to pixel location (400,400)

how do I do that?
Offline Chman

Junior Duke




Nothing more that... Java games are cool !


« Reply #1 - Posted 2004-07-25 09:06:22 »

If I understand your question, you want to draw a 2D quad.
First you should turn OpenGL view mode into Ortho mode (2D), and then draw the quad using something like :

1  
2  
3  
4  
5  
6  
glBegin(GL_QUADS);
   glVertex2i(200,200);
   glVertex2i(400,200);
   glVertex2i(400,400);
   glVertex2i(200,400);
glEnd();


....in the rendering loop.

You should take a look at Nehe's tutorials (look at the LWJGL ports down the "First Polygon" tutorial page).

Chman
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #2 - Posted 2004-07-25 11:39:02 »

Doesn't LWJGL setup an ortho view for you as a default now? With one pixel to one openGL unit, just how you're after.

...and you might want to add a glColor3f(r, g, b) in there as well.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nech_neb

Junior Duke




Java for LIFE !!!


« Reply #3 - Posted 2004-07-25 18:17:43 »

All the Nehe Tutorials seem to draw the  quads using

GL11.glVertex3f


Hmm, I can't seem to get it working....

I'm doing

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
      public void render()
      {
            GL11.glLoadIdentity();                                              // Reset The View
            GL11.glOrtho(0, 640, 0, 480, -1, 1);
            draw2DQuad(0,0,200,200);
      }

      private void draw2DQuad(int x1, int y1, int x2, int y2)
      {
            GL11.glBegin(GL11.GL_QUADS);
                  GL11.glTexCoord2f(0.0f, 1.0f);                                      // First Texture Coord
                  GL11.glVertex2i(x1,y1);
                 
                  GL11.glTexCoord2f(1.0f, 1.0f);                                      // Second Texture Coord
                  GL11.glVertex2i(x2,y1);
                 
                  GL11.glTexCoord2f(1.0f, 0.0f);                                      // Third Texture Coord
                  GL11.glVertex2i(x2,y2);
                 
                  GL11.glTexCoord2f(0.0f, 0.0f);                                      // Fourth Texture Coord
                  GL11.glVertex2i(x1,y2);
            GL11.glEnd();            
      }


If I do a

1  
GL11.glTranslatef(0.0f, 0.0f, -2.0f);


after the glLoadIdentity, I can see the
quad on the screen, but not a the location where
I specified it do be....

Cry
Offline ribot

Junior Duke




Ribot - mobile UI specialist


« Reply #4 - Posted 2004-07-25 18:21:42 »

This is what I use for JOGL:

you would use code like the following to make sure you are using an orthagonal setup:

Quote


           gl.glViewport(0, 0, width, height);
           gl.glMatrixMode(GL.GL_PROJECTION);
           gl.glLoadIdentity();
           gl.glOrtho(0.0f, width, 0.0f, height, 0.0f, 10000.0f);
           gl.glMatrixMode(GL.GL_MODELVIEW);
           gl.glLoadIdentity();



the above code should be placed inside your reshape method so that you can draw a quad using the following at your intended location (placed inside your display method:

Quote

// Make sure you set a drawing state colour before you continue with the following code:
gl.glBegin(GL.GL_QUADS);
 gl.glVertex2f(200.0f, 200.0f);
 gl.glVertex2f(400.0f, 200.0f);
 gl.glVertex2f(400.0f, 400.0f);
 gl.glVertex2f(200.0f, 400.0f);
gl.glEnd();


Spend some time looking at the nehe demos as people have pointed towards above this post.  Lots of good stuff to be learnt there.  :D

edit - fixed some spellings.  :)

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2004-07-25 18:49:34 »

Quote
All the Nehe Tutorials seem to draw the  quads using

GL11.glVertex3f

Lots of methods have slightly different names to indicate what parameters they take. 3f for three floats for example. Usually for ones that take less parameters (like 2i) the third one just ends up defaulting to 0, which is just fine for most 2d stuff.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
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 (36 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 (69 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!