[Open GL] Multitexture blending

Discussion about everything. New games, 3d math, development tips...
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

[Open GL] Multitexture blending

Post by serengeor »

I have been trying to fix this for hours, but I don't even have a clue what is wrong with it.

What I get now is this:
Image

The code used to render the mesh:

Code: Select all

glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
 
 
    glNormalPointer(GL_FLOAT, sizeof(Vertex3d), &_vertices[0].normal);
 
    glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(Vertex3d), &_vertices[0].color.color[0]);
 
    glVertexPointer(3, GL_FLOAT, sizeof(Vertex3d), &_vertices[0].position);
 
    glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_SHORT, &_indexes[0]);
 
    glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_NORMAL_ARRAY);
I'd appreciate any hints.
Last edited by serengeor on Fri Feb 10, 2012 6:47 pm, edited 1 time in total.
Working on game: Marrbles (Currently stopped).
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Incorrect opengl lighting :?

Post by mongoose7 »

Err, color[0] is opacity? Maybe you should use &color[1]?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Incorrect opengl lighting :?

Post by serengeor »

mongoose7 wrote:Err, color[0] is opacity? Maybe you should use &color[1]?
no, it is RGBA.
The problem is that only those vertices that you see in yellow are affected by light (yellow ambient and diffuse light), others stay back no mater where i move the light.
Any more ideas?
Last edited by serengeor on Sun Jan 15, 2012 12:29 pm, edited 1 time in total.
Working on game: Marrbles (Currently stopped).
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Incorrect opengl lighting :?

Post by hendu »

Maybe the vertex colors just are that wacky?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Incorrect opengl lighting :?

Post by serengeor »

hendu wrote:Maybe the vertex colors just are that wacky?
they are all set to 0,0,0,255 (not using the ones loaded right now).
Working on game: Marrbles (Currently stopped).
booe
Posts: 76
Joined: Thu Jul 29, 2010 2:12 pm

Re: Incorrect opengl lighting :?

Post by booe »

OH MY GOD! Sheep-cutie is still here!


@topic - has sheepie tried disabling vertex colors? How mesh looks with opengl lighting turned off? Are normals OK ?
booe
Posts: 76
Joined: Thu Jul 29, 2010 2:12 pm

Re: Incorrect opengl lighting :?

Post by booe »

serengeor wrote:
hendu wrote:Maybe the vertex colors just are that wacky?
they are all set to 0,0,0,255 (not using the ones loaded right now).

Code: Select all

glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(Vertex3d), &_vertices[0].color.color[0]);
 
WOOOOOOHOOOOOOOO!
You're passing number three as first argument, which means "RGB", not "RGBA"!
Have you tried to change '3' to '4' ?

What's the layout of your Vertex3d::color, huh?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Incorrect opengl lighting :?

Post by serengeor »

booe wrote:OH MY GOD! Sheep-cutie is still here!


@topic - has sheepie tried disabling vertex colors? How mesh looks with opengl lighting turned off? Are normals OK ?
disabling vertex colors results in (same as if I would just set them to white color) whole mesh being yellow and the same vertices as before are being only affected by light.
Image

I'm unsure about the normals, they are loaded as the whole mesh with assimp.
Working on game: Marrbles (Currently stopped).
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Incorrect opengl lighting :?

Post by serengeor »

booe wrote: WOOOOOOHOOOOOOOO!
You're passing number three as first argument, which means "RGB", not "RGBA"!
Have you tried to change '3' to '4' ?

What's the layout of your Vertex3d::color, huh?
Nothing changes if i use 4 or 3. (since it is RGBA and RGB).
The color is:

Code: Select all

boost::uint8_t color[4];
I'm pretty sure that color is not the problem as it is displayed correctly without lighting.

I'm trying to implement normal drawer right now to see how the normals look, but I'm having a bit of trouble.

EDIT: Made to draw them:
Image

Drawing code:

Code: Select all

 
void COpenGLRenderer::renderMeshNormals(IMeshBuffer * buffer)
{
    if(m_currentMaterial->getFlag(EMRF_LIGHTING)) glDisable(GL_LIGHTING);
 
    VertexArray lines;
    IndexArray indexes;
    for (boost::uint16_t i = 0; i<buffer->getVertexCount(); i++)
    {
        lines.push_back(buffer->getVertices()[i].position);
        lines.push_back(buffer->getVertices()[i].position+buffer->getVertices()[i].normal);
 
        indexes.push_back(indexes.size());
        indexes.push_back(indexes.size());
 
    }
 
    glEnableClientState(GL_VERTEX_ARRAY);
 
    glVertexPointer(3, GL_FLOAT, sizeof(Vertex3d), &lines.data()[0].position[0]);
    glDrawElements(GL_LINES, indexes.size(), GL_UNSIGNED_SHORT, &indexes.data()[0]);
 
    glDisableClientState(GL_VERTEX_ARRAY);
    
    if(m_currentMaterial->getFlag(EMRF_LIGHTING)) glEnable(GL_LIGHTING);
 
}
Working on game: Marrbles (Currently stopped).
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Re: Incorrect opengl lighting :?

Post by ent1ty »

Well, to cheer you up, I think it looks real good. You just put some ghosts into your game and tell everyone it's supposed to be like this. And use lightmapped textures for level geometry instead of dynamic lighting.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Incorrect opengl lighting :?

Post by serengeor »

ent1ty wrote:Well, to cheer you up, I think it looks real good. You just put some ghosts into your game and tell everyone it's supposed to be like this. And use lightmapped textures for level geometry instead of dynamic lighting.
Heh, could do that if I was building a game right now.
But I'm doing my little rendering engine and I need to fix the strange normals somehow. I certainly wouldn't use these lights in game.
Working on game: Marrbles (Currently stopped).
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Incorrect opengl lighting :?

Post by Cube_ »

that is one really cool screenshot. mind if I borrow the code?
"this is not the bottleneck you are looking for"
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Re: Incorrect opengl lighting :?

Post by ent1ty »

uhm... you just set all the vertex normals to [0,|1|,0] and you're good to go
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Incorrect opengl lighting :?

Post by serengeor »

aaammmsterdddam wrote:that is one really cool screenshot. mind if I borrow the code?
Sure.
ent1ty wrote: uhm... you just set all the vertex normals to [0,|1|,0] and you're good to go
Tried that and all I can say is that something really weird going on in my code :/
If I load the blender monkey I can't even see the normals though the head renders ok.
Working on game: Marrbles (Currently stopped).
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Incorrect opengl lighting :?

Post by serengeor »

After hours of wall meats head, I finally managed to fix. And the problem was normals.. I forgot to copy over normal data in Vertex3d constructor :lol:

Here's a screenie of working (probably correctly :D) ligth:
Image
PS. triangle indicates light position.

Thank you all for your responses :wink:
Working on game: Marrbles (Currently stopped).
Post Reply