Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: GL_FLAT looks ugly - I see triangles instead of quads

  1. #1
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    1

    GL_FLAT looks ugly - I see triangles instead of quads

    Hi,

    I'm writing my own library/engine based on OpenGL. I've just started implementing lighting. When I created a sphere or plane (my own models), placed them in [0, 0, 0], set lighting mode to GL_FLAT I got this:




    where I expected something like this (sample image from web):



    These ugly triangles appear instead of quads!

    The light parameters in plane scene are:
    - position = [0, 5, 0, 1],
    - ambient = [0, 0, 0, 1],
    - diffuse = [1, 1, 1, 1],
    - specular = [0, 0, 0, 1],
    other are default.

    The light position in sphere scene is [10, 0, 10 ,1], other parameters the same as before.

    The plane is a square of size 20, it's composed of 20x20x2 triangles (2 triangles per small square). Normals of each vertex [0, 1, 0].

    The sphere's radius is 2, it has 20 meridians and 18 latitude-lines (+ 2 poles), so 2x20 triangles at poles, and 20x17x2 triangles in the rest of it. Normals of each vertex are vectors, which would have connect this vertex with center of sphere, if they'd be longer.

    Both models materials are:
    - ambient = [0, 0, 0, 1],
    - diffuse = [1, 1, 1, 1],
    - specular = [0, 0, 0, 1],
    - shininess = 0.

    I'm rendering using GL_TRIANGLES. So I thought that changing this to GL_QUADS will help. It did, but two new issues appeared:
    - i heard that GL_QUADS are depraciated,
    - when I look at a broken quad (not planar) from very close distance, it's inner (broken) edge suddenly flips (so it's broken the other way).

    I thought it's a problem with normals, but then I made this plane from first image (at the beginning it was only the sphere), with all normals = [0, 1, 0], and you see what I got.

    So I have no idea what can cause this problem. Maybe you have?

    I would show my code, but for now my library has about 40 classes. It's really hard to show key fragments. I would have to introduce you to entire logic and way of thinking in my library, and it would take too much time and too much writing.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,211
    Quote Originally Posted by Sushi271 View Post
    Hi,

    I'm writing my own library/engine based on OpenGL. I've just started implementing lighting. When I created a sphere or plane (my own models), placed them in [0, 0, 0], set lighting mode to GL_FLAT I got this ... I'm rendering using GL_TRIANGLES. So I thought that changing this to GL_QUADS will help. It did, but two new issues appeared:
    - i heard that GL_QUADS are depraciated,
    - when I look at a broken quad (not planar) from very close distance, it's inner (broken) edge suddenly flips (so it's broken the other way).
    As to the first, QUADS are still there in the compatibility profile (the default). Deprecation/removal only affects you if you target the core profile. glShadeModel as well as fixed function lighting is also deprecated, but again, this only affects you in the core profile.

    As to the second, what do you mean "broken"?

    Also, GL_FLAT is shading thing, not a lighting thing (shading comes after lighting).
    Last edited by Dark Photon; 12-09-2012 at 12:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •