Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Cube decided not to participate.  (Read 1134 times)
0 Members and 1 Guest are viewing this topic.
Offline Joshua Waring
« Posted 2012-10-17 10:57:48 »

All I'm trying to do is display a 3D cube with Ortho and I have no idea but nothing appears. although everything is in range O.o it has confused me to the next level to the point of > 9000

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  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

public class shadows{
   public static double angle = 0;
   
   public static void init(){
      try {
         Display.create();
         Display.setDisplayMode(new DisplayMode(800, 600));
         Display.setTitle("");
         
         GL11.glMatrixMode(GL11.GL_PROJECTION);
         GL11.glLoadIdentity();
         GL11.glOrtho(-10, 10, -10, 10, 10, -10);
         GL11.glMatrixMode(GL11.GL_MODELVIEW);
         GL11.glLoadIdentity();
         
         GL11.glEnable(GL11.GL_DEPTH_TEST);
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
     
     
   }

   public static void renderLoop(){
      while(!Display.isCloseRequested()){
         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
         GL11.glClearColor(0, 0, 1, 1);
         GL11.glLoadIdentity();
         
         GL11.glColor3d(1,   1, 1);
         GL11.glBegin(GL11.GL_QUADS);
            // front
            GL11.glVertex3f(-1, -1, 1);
            GL11.glVertex3f(-1,  1, 1);
            GL11.glVertex3f( 1,  1, 1);
            GL11.glVertex3f( 1, -1, 1);
            //back
            GL11.glVertex3f(-1, -1, -1);
            GL11.glVertex3f(-1,  1, -1);
            GL11.glVertex3f( 1,  1, -1);
            GL11.glVertex3f( 1, -1, -1);
            // right
            GL11.glVertex3f( 1, -1, 1);
            GL11.glVertex3f( 1,  1, 1);
            GL11.glVertex3f( 1,  1,-1);
            GL11.glVertex3f( 1, -1,-1);
            // left
            GL11.glVertex3f(-1, -1, 1);
            GL11.glVertex3f(-1,  1, 1);
            GL11.glVertex3f(-1,  1,-1);
            GL11.glVertex3f(-1, -1,-1);
            // bottom
            GL11.glVertex3f(-1, -1, 1);
            GL11.glVertex3f(-1, -1,-1);
            GL11.glVertex3f( 1, -1,-1);
            GL11.glVertex3f( 1, -1, 1);
            // Top
            GL11.glVertex3f(-1,  1, 1);
            GL11.glVertex3f(-1,  1,-1);
            GL11.glVertex3f( 1,  1,-1);
            GL11.glVertex3f( 1,  1, 1);
         GL11.glEnd();
         
         Display.update();
         Display.sync(30);
         System.out.println("Frame Rendered");
      }
      cleanup();
   }
   
   public static void cleanup(){
      Display.destroy();
   }
   public static void main(String[] args){
      init();
      renderLoop();
      System.exit(0);
   }
}

The world is big, so learn it in small bytes.
Online RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #1 - Posted 2012-10-17 12:46:37 »

For 2D rendering you normally use this line:
GL11.glOrtho(0, Panel.getWidth(), Panel.getHeight(), 0, mindepth, maxdepth);

I dont know what all these 10 and -10 are supposed to do.
Also the cube is really small, but i guess that can be fixed by choosing a smaller glortho.

1  
2  
3  
4  
5  
6  
7  
void glOrtho(
   GLdouble     left,
    GLdouble     right,
    GLdouble     bottom,
    GLdouble     top,
    GLdouble     nearVal,
    GLdouble     farVal);

Offline Joshua Waring
« Reply #2 - Posted 2012-10-17 15:42:54 »

I think the main problem here is I don't understand why I can't have the values at -10 to 10 in Ortho and still work normally...

The world is big, so learn it in small bytes.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Magn919

Junior Devvie


Medals: 6
Exp: 4 years



« Reply #3 - Posted 2012-10-17 16:12:46 »

try doing glViewport(0, 0, 800, 600); right after creating the display.

For every new problem, a new source of solutions has come to exist.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 842
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2012-10-17 17:11:49 »

Always start with the most simple code you can imagine. Why not render a triangle or quad first? Then you have at least something on screen, and work from there.

You can look at this tutorial:
 - introduction to vertex arrays and vertex buffer objects (opengl)

Ignore everything about vertex arrays and vertex buffer objects - one of the first methods shows how to draw a triangle.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Joshua Waring
« Reply #5 - Posted 2012-10-18 12:32:09 »

VICTORY, view port has fixed it, but if you don't mind me asking... Why?

The world is big, so learn it in small bytes.
Offline Joshua Waring
« Reply #6 - Posted 2012-10-18 14:03:09 »

I didn't want to create a new topic about this so I'll paste the question here

When it comes to placing the values into glLight with a buffer, the majority of the tutorials I don't understand why we don't just place things directly into a FloatBuffer instead of a ByteBuffer.
1  
2  
3  
4  
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(16);
byteBuffer.order(ByteOrder.nativeOrder( ) );
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, (FloatBuffer) byteBuffer.asFloatBuffer().put(light0Position).flip());
   

instead of
1  
2  
3  
4  
private FloatBuffer lightPosition;
lightPosition = BufferUtils.createFloatBuffer(4);
lightPosition.put(1.0f).put(1.0f).put(1.0f).put(0.0f).flip();
glLight(GL_LIGHT0, GL_POSITION, lightPosition);                         // sets light positio

The world is big, so learn it in small bytes.
Offline Magn919

Junior Devvie


Medals: 6
Exp: 4 years



« Reply #7 - Posted 2012-10-18 16:27:32 »

The viewport is set automatically to whatever the display resolution is set to when created.
but you set the resolution after creating the window, so you had to set it manually.

For every new problem, a new source of solutions has come to exist.
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 (36 views)
2014-12-15 09:26:44

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

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

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

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

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

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

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

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

toopeicgaming1999 (37 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!