Results 1 to 6 of 6

Thread: help me with built in function for spehere in openGL

  1. #1
    Member Contributor
    Join Date
    Oct 2002
    Location
    bangalore
    Posts
    56

    help me with built in function for spehere in openGL

    Hello all,
    pls tell me if openGL has built in function for drawing a sphere.
    and also how to chanhe the surface color of that with 2 colors at a time??
    thanks & regards
    Prashant G.P

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: help me with built in function for spehere in openGL

    openGL does not have any primitive object, they all have to be drawn with librarys like glu or glut.

    glutSolidSphere or glutWireSphere but only one color can be use at a time.

    with gluSphere you can only use one color at a time but you can apply a texture map with the two diffrent colors.

    The other option would to make the sphere yourself and map the colors per triangle or quad. The are examples of building your own sphere's.


    Originally posted by prashantgp:
    Hello all,
    pls tell me if openGL has built in function for drawing a sphere.
    and also how to chanhe the surface color of that with 2 colors at a time??

  3. #3
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: help me with built in function for spehere in openGL

    Hi !

    If you want to do it yourself it's pretty simple, you can also peek at the source code of the OpenGL sample implementation or the Mesa source code (www.sourceforge.net).

    Mikael

  4. #4
    Member Newbie
    Join Date
    Nov 2002
    Location
    Germany
    Posts
    48

    Re: help me with built in function for spehere in openGL

    Here is the algorhythm I've coded a view days ago for testing purposes... it's slow and needs optimization, use display lists with that one:

    void MDrawSphere(float size,float segs,float pps) {
    float ss = M_PI / segs,ps = M_PI / (pps / 2);

    glBegin(GL_QUADS);
    for (float seg = 0;seg < M_PI;seg += ss)
    for (float pol = -M_PI;pol < M_PI;pol += ps) {
    glColor3f(fabs(cos(pol)),fabs(cos(seg)),0);
    glVertex3f(cos(pol) * sin(seg) * size,cos(seg) * size,sin(pol) * sin(seg) * size);
    glColor3f(fabs(cos(pol + ps)),fabs(cos(seg)),0);
    glVertex3f(cos(pol + ps) * sin(seg) * size,cos(seg) * size,sin(pol + ps) * sin(seg) * size);
    glColor3f(fabs(cos(pol + ps)),fabs(cos(seg + ss)),0);
    glVertex3f(cos(pol + ps) * sin(seg + ss) * size,cos(seg + ss) * size,sin(pol + ps) * sin(seg + ss) * size);
    glColor3f(fabs(cos(pol)),fabs(cos(seg + ss)),0);
    glVertex3f(cos(pol) * sin(seg + ss) * size,cos(seg + ss) * size,sin(pol) * sin(seg + ss) * size);
    }
    glEnd();
    }

    You should remove/change the glColor3f() calls within the function to use your own coloring/texturing/materialing.

    MDrawSphere(<size>,<segments>,<quads-per-segment> );

    Here is the result of MDrawSphere(1,16,32) with smooth shading (rotated):



    [This message has been edited by mm_freak (edited 11-06-2002).]
    Knowledge is Power

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: help me with built in function for spehere in openGL

    Hi !

    If you just replace all the sin/cos calls with a single call at the top saving the result in local variables should speed it all up.

    Mikael

  6. #6
    Member Newbie
    Join Date
    Nov 2002
    Location
    Germany
    Posts
    48

    Re: help me with built in function for spehere in openGL

    I know, that was just a test and I'm not gonna optimize it. Normally I write such algorhythms in assembler (if they don't need to be portable).

    [This message has been edited by mm_freak (edited 11-08-2002).]
    Knowledge is Power

Similar Threads

  1. where has built-in variable "gl_FragColor" gone in OpenGL 4.4?
    By zzzhhh in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-08-2014, 09:27 AM
  2. Why must OpenGL projects be built? (CMake, premake, etc)
    By Areyan in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 11-12-2012, 11:17 AM
  3. How will I know which OpenGL version a game is built on
    By komali_r in forum OpenGL: User Software
    Replies: 1
    Last Post: 08-15-2012, 12:44 AM
  4. Built-in random function
    By pelotoescogorciao in forum OpenCL
    Replies: 1
    Last Post: 01-25-2012, 03:36 AM
  5. Linear Falloff on Built-in OpenGL Lighting
    By Heru Feanor in forum OpenGL: General
    Replies: 1
    Last Post: 05-27-2004, 10:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean