Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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  
  Only objects with textures are visible  (Read 1633 times)
0 Members and 1 Guest are viewing this topic.
Offline RylandAlmanza

Junior Member


Medals: 3



« Posted 2012-03-02 02:32:38 »

So, I changed my initGL() function to include lighting in my game. Works great for textured objects, but If I make a colored cube with no texture, I don't see it. Here's my initGL() function:
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  
protected void initGL() {
      int width = display_parent.getWidth();
      int height = display_parent.getHeight();
      GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
       GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
       GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
       GL11.glClearDepth(1.0f); // Depth Buffer Setup
       GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
       GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do

        // Calculate The Aspect Ratio Of The Window
       GLU.gluPerspective(45.0f, (float) width / (float) height, height, -height);
        GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

        // Really Nice Perspective Calculations
       GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
        ByteBuffer temp = ByteBuffer.allocateDirect(16);
        temp.order(ByteOrder.nativeOrder());
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip());              // Setup The Ambient Light
       GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip());              // Setup The Diffuse Light
       GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip());         // Position The Light
       GL11.glEnable(GL11.GL_LIGHT1);
       
        GL11.glEnable(GL11.GL_LIGHTING);
   }

Anyone see anything wrong with it?
Offline theagentd
« Reply #1 - Posted 2012-03-02 11:33:32 »

I'd guess you keep a texture bound and just don't send texture coordinates, right? glTexCoord works just like glColor, meaning that if you don't specify texture coordinates for the next glVertex calls then they are all going to use the last value. That means that the texture is going to sample at a single location and put that color on the whole triangle/quad/line/whatever, which in your case might be black. Try to either unbind the texture (glBindTexture(GL_TEXTURE_2D, 0)Wink or disable texturing (glDisable(GL_TEXTURE_2D)Wink.

Myomyomyo.
Offline RylandAlmanza

Junior Member


Medals: 3



« Reply #2 - Posted 2012-03-02 20:48:53 »

I changed this:
1  
GLU.gluPerspective(45.0f, (float) width / (float) height, height, -height);

to this:
1  
GL11.glOrtho( -width/2, width/2, -height/2, height/2, -height, height );

And problem solved! Still not sure why, though. Can someone explain?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2012-03-02 20:55:33 »

1  
GLU.gluPerspective(45.0f, (float) width / (float) height, height, -height);
the zNear, zFar values are a bit off.

1  
GLU.gluPerspective(45.0f, (float) width / (float) height, nearZero, over9000);

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline RylandAlmanza

Junior Member


Medals: 3



« Reply #4 - Posted 2012-03-02 21:08:49 »

So, this should work?
1  
GLU.gluPerspective(45.0f, (float) width / (float) height, .1f, height);

Cause it made my objects invisible again. Sad
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2012-03-02 21:10:37 »

Then you aim your camera in the wrong direction (the objects are behind the camera)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
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.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (10 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (107 views)
2014-04-08 23:06:04

tom_mai78101 (207 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!