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: Draw a star

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    2

    Draw a star

    Please help me... i want to draw a star in opengl...im have a basic with opengl..im try to do by myself..but..the result is disapointed for me..please check my source code...where part im wrong for this code??...this is the code..





    #include <GL/glut.h>
    void display (void)
    {

    glClear (GL_COLOR_BUFFER_BIT);
    glLoadIdentity ();
    gluLookAt (0.0,0.0,0.5,0.0,0.0,0.0,0.0,1.0,0.0);

    glBegin (GL_LINES);
    glVertex3f(0.0,0.2,0.0);
    glVertex3f(0.1,0.1,0.0);
    glVertex3f(0.2,0.05,0.0);
    glVertext3f(0.1,0.0,0.0);
    glVertex3f(0.2,-0.1,0.0);
    glVertex3f(0.0,0.0,0.0);
    glVertex3f(-0.2,-0.1,0.0);
    glVertex3f(-0.1,0.0,0.0);
    glVertex3f(-0.2,0.05,0.0);
    glVertex3f(-0.1,0.1,0.0);
    glEnd();
    glFlush();
    }

    void keyboard (unsigned char key, int x, int y)
    {

    if(key == 27)
    {
    exit(0);
    }
    }

    void reshape (int width, int height)
    {

    glViewport(0, 0, (GLsizei) width, (GLsizei) height);
    glMatrixMode (GL_PROJECTION) ;
    glLoadIdentity ();
    glOrtho (-1.0,1.0,-1.0,1.0,-1.0,1.0);
    glMatrixMode (GL_MODELVIEW);
    }

    int main(int argc, char **argv)
    {
    glutInit (&amp;argc, argv);
    glutInitWindowSize (800,600);
    glutInitWindowPosition (100,100);
    glutCreateWindow ("ex4");
    glutDisplayFunc (display);
    glutReshapeFunc (reshape);
    glutKeyboardFunc (keyboard);
    glutMainLoop ();
    return 0;
    }

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    258

    Re: Draw a star

    You almost got it.

    Just change
    > glBegin (GL_LINES);
    to
    glBegin (GL_LINE_LOOP);

    GL_LINES means you will draw separate line segments (two vertices per line).
    GL_LINE_LOOP connects each vertex with another with a line segment, and than the last vertex is connected to the first one.

Posting Permissions

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