Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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  
  [SOLVED] LWJGL Visual Illusion Problem  (Read 404 times)
0 Members and 1 Guest are viewing this topic.
Offline Vladiedoo

Senior Member


Medals: 11



« Posted 2012-11-20 01:01:45 »

Hi, so I obtained source code from http://www.youtube.com/watch?v=O0xtgfcxcq0&feature=plcp but noticed a strange visual effect.

I plugged in the code and when looking directly down onto a block this occurred.




I have jumped around with learning OpenGL but I've firmly started recently but I havn't been able to resolve the issue, yet.

Here is parts of the code that hopefully explains the problem
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  
      static int width=800, height=600;
// ---------------------------------------------------------------------------------
     DisplayMode dm = new DisplayMode(width,height);
      for(DisplayMode mode : Display.getAvailableDisplayModes()){
         if(mode.getWidth() == 800 && mode.getHeight() == 600 && mode.isFullscreenCapable() && mode.getBitsPerPixel() == 32){
            dm = mode;
            break;
         }
      }
      if(dm.isFullscreenCapable()) Display.setFullscreen(false);
      Display.setDisplayMode(dm);
      Display.create();
// ------------------------------------------------------------------------------------

   private void initGL3() {
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();

      GLU.gluPerspective((float) 100, App.width / App.height, 0.001f, 1000);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);

      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glShadeModel(GL11.GL_SMOOTH);
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
      GL11.glClearDepth(1.0f);
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      GL11.glDepthFunc(GL11.GL_LEQUAL);
   }

//    This is one of the crates that are being drawn.
//    float startX, float startY, float startZ, float endX, float endY, float endZ, Texture texSurround
     collidable.add(new PolyVoxel(20, 0.1f, 2, 22, 2, 4, texCrate));

// Rotation values are created from mouse movement (FPS camera).
  public void translateCamera() {
      GL11.glRotatef(rotation.x, 1, 0, 0);
      GL11.glRotatef(rotation.y, 0, 1, 0);
      GL11.glRotatef(rotation.z, 0, 0, 1);
      GL11.glTranslatef(-vector.x, -vector.y - 1.4f, -vector.z);
   }


Sorry for the long post, if someone could point me in the right direction I would be grateful, thanks for your time.
Offline theagentd
« Reply #1 - Posted 2012-11-20 01:33:56 »

Your call to GLU.gluPerspective() most likely screws up the aspect ratio. App.width and App.height are both ints, right? That means that App.width / App.height = 1 in most cases since effectively the decimals are getting cut off. You should just change it to
1  
(float)App.width / App.height

which should solve the problem.

Myomyomyo.
Offline Orangy Tang

JGO Kernel


Medals: 48
Projects: 11


Monkey for a head


« Reply #2 - Posted 2012-11-20 01:34:14 »

That usually means you've got your aspect ratio (second parameter to gluPerspective) wrong.

Are App.width and App.height ints? Because you may be getting integer divide so your aspect is incorrectly 1 rather than 1.6 (or whatever).

Edit: Spooky double post! persecutioncomplex

[ 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 theagentd
« Reply #3 - Posted 2012-11-20 01:35:26 »

18 seconds too slow, sucker!  Grin

Myomyomyo.
Offline Vladiedoo

Senior Member


Medals: 11



« Reply #4 - Posted 2012-11-20 01:36:45 »

[size=10pt]Excellent![/size] Thank you so much, that solved the issue. (Credits go to the answer that is 18 seconds faster of course  Pointing)
Offline theagentd
« Reply #5 - Posted 2012-11-20 01:50:50 »

[size=10pt]Excellent![/size] Thank you so much, that solved the issue. (Credits go to the answer that is 18 seconds faster of course  Pointing)
Yatta! Cool

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (57 views)
2013-05-17 21:29:12

alaslipknot (66 views)
2013-05-16 21:24:48

gouessej (96 views)
2013-05-16 00:53:38

gouessej (93 views)
2013-05-16 00:17:58

theagentd (104 views)
2013-05-15 15:01:13

theagentd (95 views)
2013-05-15 15:00:54

StreetDoggy (141 views)
2013-05-14 15:56:26

kutucuk (163 views)
2013-05-12 17:10:36

kutucuk (162 views)
2013-05-12 15:36:09

UnluckyDevil (172 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.159 seconds with 20 queries.