Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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 1771 times)
0 Members and 1 Guest are viewing this topic.
Offline RylandAlmanza

Junior Devvie


Medals: 3



« Posted 2012-03-02 01: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

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #1 - Posted 2012-03-02 10: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 Devvie


Medals: 3



« Reply #2 - Posted 2012-03-02 19: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: 836
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2012-03-02 19: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 Devvie


Medals: 3



« Reply #4 - Posted 2012-03-02 20: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: 836
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2012-03-02 20: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.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
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!