Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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] Problem with light (I think)  (Read 1355 times)
0 Members and 1 Guest are viewing this topic.
Offline Supamagier

Senior Newbie





« Posted 2009-09-05 12:20:47 »

Hey all,

I created a 3D engine for a game I'm making, but I have a little problem. I think the problem has to do with the lighting, but I'm not sure. I was wondering if someone could help me out.

An image says a thousand words... so I attached an image explaining the problem. The left barbell, the correct one, is imported from a working OBJ importer I found. The one on the right is from my own loader, based on the working one.

As I said, I think the problem has to do with the lighting, but I'm not sure... Anyone help, please?

~Matt

P.S.: I'm pretty sure it's the light, because if I render it without light & with the correct color (although it isn't really material than) it shows up fine, as far as it can without light. The image showing this is below the other.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2009-09-05 15:11:03 »

At the risk of stating the obvious, it looks like your normals are messed up. Have you tried drawing the normal for each vertex so you can see if they're pointing in the correct direction?

At a guess you've either got the components for your normals switched (x instead of y, etc.) or your normals are being associated with the wrong vertices.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2009-09-05 16:07:21 »

At a guess you've either got the components for your normals switched (x instead of y, etc.) or your normals are being associated with the wrong vertices.

The normals are definitely associated with the wrong vertices.

When the X/Y would be swapped, you'd still have perfectly smooth shading, but it would look like the light was coming from another angle.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Supamagier

Senior Newbie





« Reply #3 - Posted 2009-09-05 18:52:35 »

Normals, could be, I'll check if that's the problem.

Thanks a lot guys Cheesy Will keep you informed.

~Matt
Offline Supamagier

Senior Newbie





« Reply #4 - Posted 2009-09-06 17:43:18 »

It seems, fine, looking at the code. How would I draw the normals, can you tell me please? (A)

~Matt
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2009-09-06 17:46:58 »

To render the normals:
1. use GL_LINES
2. draw a line from the vertex to vertex+normal


Anyway, maybe you could dump some code.

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

Senior Newbie





« Reply #6 - Posted 2009-09-06 18:08:20 »

Thanks for your quick response.

Okay, I added the normals, and at a first glance, it seems completely f**ked up. :\

What I think is weird, that if I both draw the normals and the barbell itself, they only appear half (the back is completely black), if I render just the barbell, it's the same, and if I only render the normals, they appear completely. Why's that?

Of course, it also is possible I didn't correctly draw the normals. :\ Code I used the draw the normals:

1  
2  
3  
4  
5  
6  
7  
8  
9  
// This for each plane/face/whatever you call them.
gl.glBegin(GL.GL_LINES); {
                    gl.glColor3f(255,255,255);
                    for (int i = 0; i < max; ++i) {
                        point = plane.getPoint3D(i);
                        point2 = plane.getNormal(i);
                        gl.glVertex3f(point.x+point2.x,point.y+point2.y,point.z+point2.z);
                    }
                } gl.glEnd();


I rather don't release source code, but if you can't help me without, I'm willing to mail (or so) you the src.

~Matt

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2009-09-06 19:53:41 »

Each line has 2 points..


gl.glVertex3f(point.x,point.y,point.z);
gl.glVertex3f(point.x+point2.x,point.y+point2.y,point.z+point2.z);

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

Senior Newbie





« Reply #8 - Posted 2009-09-06 19:57:43 »

Yea.. I was just thinking about that. Made that after but decided to await your reaction.

Seems fine to me, although I don't know much about this stuff.

~Matt

P.S.: Same here, if I draw with the barbell, they only appear half, and completely without. Btw, it doesn't matter where I put a light, w/e the color is, but the back remains dark.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2009-09-06 20:04:15 »

I'm quite sure the normal indices you pick for your vertices are off by one.

But without sourcecode... who knows!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2009-09-06 20:42:06 »

So.. you're doing:


foreach vertex
   glVertex3f
   glNormalf
   glTexCoord2f



OpenGL is a statemachine, so it remembers every attribute until it is changed.

You must first specify the vertex attributes (normals, colors, texcoords) and then you 'finalize' it by specifying the vertex.

Currently, your texcoords and normals end up at the 'next' vertex, which has the same effect as picking the attributes at the next offset (off by one).


This fixes it:

foreach vertex
   glNormalf
   glTexCoord2f
   glVertex3f

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

Senior Newbie





« Reply #11 - Posted 2009-09-06 20:48:05 »

Thanks a lot! Cheesy
It worked, really thanks. Cheesy

Btw, did the code look okay, or was it ineffective/ugly? Please let me know, so I can improve it. Smiley

~Matt
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2009-09-06 20:56:11 »

It's goofy, but you should focus on your game.

Once you run into performance issues, there are plenty of sites to help you.

For now, make something playable, that's the hardest part.

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.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!