OpenGL: How to make surface shiny

This is a discussion on OpenGL: How to make surface shiny within the Game Programming forums, part of the General Programming Boards category; The gluCylinder I drew have a shiny surface that responds to my glMaterialfv() command, but the rectangle i drew myself ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    vancouver bc
    Posts
    28

    OpenGL: How to make surface shiny

    The gluCylinder I drew have a shiny surface that responds to my glMaterialfv() command, but the rectangle i drew myself doesn't shine at all.

    How do you draw a surface and make it shiny?

    I enable light0, give it some ambient and specular component, and give my surface and cylinder some ambient and specular material properties. the shiny feeling comes up in the cylinder, i did the same for the GL_QUADS i draw but it renders like a dead rectangle with no shiness whatsoever.

    Can someone describe to me all the steps to enable the specular property on a surface?

    ting

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    vancouver bc
    Posts
    28
    Quote Originally Posted by zacs7 View Post
    Perhaps i should elborate it a little bit. I am not having trouble with making something shiny in general. I am having trouble to make an GL_QUADS surface shiny. It is defined by the following code:

    Code:
      glBegin(GL_QUADS);
        glVertex3f(1,-1,1); //top left front
        glVertex3f(1,1,1); //top right front
        glVertex3f(-1,1,1); //top right back
        glVertex3f(-1,-1,1); // top left back
      glEnd();
    Before i draw this GL_QUADS rectangle, I put these two lines:
    Code:
      glMaterialfv(GL_FRONT, GL_AMBIENT, green);
      glMaterialfv(GL_FRONT, GL_SPECULAR, green);
    thanks for any help.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Have you defined the normals for each vertex?

    I suggest you read the entire link I gave you.

  5. #5
    Registered User
    Join Date
    Mar 2008
    Location
    vancouver bc
    Posts
    28

    Solved: glNormal determines the light reflection

    Quote Originally Posted by zacs7 View Post
    Have you defined the normals for each vertex?

    I suggest you read the entire link I gave you.
    I solved it with your help. I put the code:

    Code:
    glNormal3f(0,0,1);
    before each vertex and the front side shines exactly the way i wanted. Appriciate it.

    ting

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    112
    Could you please post your code .
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Somehow I think that hard-coded normal is not going to work in all cases.

    To get the normal you subtract two vectors to get two edge vectors. Cross these two vectors and normalize.

    Pseudocode:

    top_edge = right - left;
    left_edge = bottom - left;
    normal = normalize(cross(top_edge,left_edge))

    For better lighting you would want to determine how many edges shared a common vertex. Average the normals of the current triangle with the normals of the surrounding triangles formed by this common vertex and assign that averaged normal to the current triangle.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  2. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 10:53 AM
  3. SDL_ttf and OpenGL
    By sand_man in forum Game Programming
    Replies: 2
    Last Post: 12-01-2004, 05:06 PM
  4. MISC questions about OpenGL
    By Silvercord in forum Game Programming
    Replies: 12
    Last Post: 01-25-2003, 03:20 PM
  5. OpenGL question
    By Malek in forum Windows Programming
    Replies: 1
    Last Post: 09-10-2001, 12:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21