Jump to content
  • Advertisement
Sign in to follow this  
White Scorpion

OpenGL OpenGL lighting materials

This topic is 4882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys. Since cpp-home has been down for a few days, I must rely on you guys. I have been trying to learn the OGL API for a few days now. I am now learning how to properly light objects (the basics) but I have a question. How should rendering code be designed in an OGL application ? I thought that a simple system like this one would work, but I'm not sure.
struct Position
{
    Position( ) : x(0.0f), y(0.0f), z(0.0f) { }
    GLfloat x, y, z;
};

class CObject
{
    public:
        CObject(GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat);
        void SetColor(GLfloat, GLfloat, GLfloat);
        void SetPosition(GLfloat, GLfloata, GLfloat);
        void Render( );
    private:
        Position m_Position;
        GLfloat m_Color[3];
};

CObject::CObject(GLfloat x, GLfloat y, GLfloat z, GLfloat r, GLfloat g, GLfloat b)
{
    m_Position.x = x;
    m_Position.y = y;
    m_Position.z = z;
    m_Color[0] = r;
    m_Color[1] = g;
    m_Color[2] = b;
}

void CObject::SetColor(GLfloat r, GLfloat g, GLfloat b)
{
    m_Color[0] = r;
    m_Color[1] = g;
    m_Color[2] = b;
}

void CObject::SetPosition(GLfloat x, GLfloat y, GLfloat z)
{
    m_Position.x = x;
    m_Position.y = y;
    m_Position.z = z;
}

void CObject::Render( )
{
    glPushMatrix( );
        glTranslatef(m_Position.x, m_Position.y, m_Position.z);
        glMaterialfv(GL_FRONT, GL_DIFFUSE, m_Color);
        // whatever you need to draw...
    glPopMatrix( );
}
Any suggestion, comment is welcome.

Share this post


Link to post
Share on other sites
Advertisement
You need a fourth color component in your diffuse color array, other than that, you should be fine.
My suggestion would be to add support for shininess (1 float), emission, specular and ambient :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!