-
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 (&argc, argv);
glutInitWindowSize (800,600);
glutInitWindowPosition (100,100);
glutCreateWindow ("ex4");
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutMainLoop ();
return 0;
}
-
Member
Regular Contributor
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
-
Forum Rules