draw this shape using opengl

hi all,

i want to ask u about the following shape how can we draw it using OpenGL primitives:

http://img103.herosh.com/2011/05/10/36849501.jpg

[img]http://img103.herosh.com/2011/05/10/36849501.jpg[/img]

thank u

People here will only help when you post some code.
This is my code but it has some problems if any one can help me :
_____________________________


#include <windows.h>
#include <GL/glut.h>
#include <math.h>

void drawShapes()
{
glClear(GL_COLOR_BUFFER_BIT);

//**********************

glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0,0,0);
glBegin(GL_QUADS);
glVertex2i(10,10);
glVertex2i(10,490);
glVertex2i(390,490);
glVertex2i(390,10);
glVertex2i(10,10);
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glEnd();

//the circules
//1st one
GLfloat xi,yi,theta=0;
GLfloat x_c,y_c,r;
int count;

x_c=200,y_c=250,r=160;
glBegin(GL_POLYGON);
for(count=1;count<=10000;count++)
{
theta=theta+0.001;
xi=x_c + r * cos (theta);
yi=y_c + r * sin (theta);
glColor3f(1,0,1);
glVertex2d(xi,yi);
}
glEnd();

//2nd one
x_c=200,y_c=250,r=130;
glBegin(GL_POLYGON);
for(count=1;count<=10000;count++)
{
theta=theta+0.001;
xi=x_c + r * cos (theta);
yi=y_c + r * sin (theta);
glColor3f(0,0,1);
glVertex2d(xi,yi);
}
glEnd();

//3rdcircle
x_c=200,y_c=250,r=115;
glBegin(GL_POLYGON);
for(count=1;count<=10000;count++)
{
theta=theta+0.001;
xi=x_c + r * cos (theta);
yi=y_c + r * sin (theta);
glColor3f(0.5,0.5,1);
glVertex2d(xi,yi);
}
glEnd();
//4thcircle
x_c=200,y_c=250,r=90;
glBegin(GL_POLYGON);
for(count=1;count<=10000;count++)
{
theta=theta+0.001;
xi=x_c + r * cos (theta);
yi=y_c + r * sin (theta);
glColor3f(0,0,0);
glVertex2d(xi,yi);
}
glEnd();

//THE POLYGON

glColor3f(1.0f, 1.0f, 1.0f); // sets color
glBegin(GL_POLYGON);
glVertex2i(100, 100); // vertex 1
glVertex2f(200, 100); // vertex 2
glVertex2f(200, 200); // vertex 3
glVertex2f(100, 200); // vertex 4

glEnd();
glFlush();
glTranslatef(50,10 ,0);
//TRIANGLES
//1
glBegin(GL_TRIANGLES);
glColor3f(.2,1,0.5);
glVertex2i(160,210);
glVertex2i(220,220);
glVertex2i(190,240);
glEnd();
glTranslatef(50,10 ,0);

//2
glBegin(GL_TRIANGLES);
glColor3f(1,1,0);
glVertex2i(150,110);
glVertex2i(200,200);
glVertex2i(190,120);
glEnd();
glTranslatef(88 ,80 ,0);
glEnd();
//3
glBegin(GL_TRIANGLES);
glColor3f(.2,1,0.5);
glVertex2i(160,210);
glVertex2i(220,220);
glVertex2i(190,240);

glFlush();
glRotatef(180,0,0,1);
glTranslatef(0 ,10 ,0);
glEnd();
//4

glBegin(GL_TRIANGLES);
glColor3f(1,1,0);
glVertex2i(150,110);
glVertex2i(200,200);
glVertex2i(190,120);

glRotatef(180,0,0,1);
glTranslatef(10 ,90 ,0);
glEnd();

glFlush();
}

void Initial ()
{
glClearColor(1,1,1,1);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0,400,0,500);
}

//main

void main()
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize (320,400);
glutInitWindowPosition (50,50);
glutCreateWindow("Shapes");
Initial();
glutDisplayFunc(drawShapes);
glutMainLoop();
}
[code] "Please use code tags" [/code]
http://www.cplusplus.com/forum/articles/40071/#msg218019

main must return int
edit: glutInit() ?
1
2
3
4
5
6
7
8
glBegin(GL_QUADS);
glVertex2i(10,10); //1
glVertex2i(10,490); //2
glVertex2i(390,490); //3
glVertex2i(390,10); //4
glVertex2i(10,10); //5?
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glEnd();


You could use gluDisk() for the circles (then a scale?)
Last edited on
plz help me :(

this is my code I modify it and i get good result but when the output window resized , u see some problem i dont no why!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    #include <windows.h>
#include <GL/glut.h>
#include <math.h>

void drawShapes()
{

 //the circules
  //1st one
  GLfloat  xi,yi,theta=0;
  GLfloat x_c,y_c,r;
  int count;

  x_c=200,y_c=250,r=160;
  glBegin(GL_POLYGON);
  for(count=1;count<=10000;count++)
  {
  theta=theta+0.001;
  xi=x_c + r * cos (theta);
  yi=y_c + r * sin (theta);
  glColor3f(1,0,1);
  glVertex2d(xi,yi);
  }
  glEnd();

 //2nd one
  x_c=200,y_c=250,r=130;
  glBegin(GL_POLYGON);
  for(count=1;count<=10000;count++)
  {
  theta=theta+0.001;
  xi=x_c + r * cos (theta);
  yi=y_c + r * sin (theta);
  glColor3f(0,0,1);
  glVertex2d(xi,yi);
  }
  glEnd();

  //3rdcircle
  x_c=200,y_c=250,r=115;
  glBegin(GL_POLYGON);
  for(count=1;count<=10000;count++)
  {
  theta=theta+0.001;
  xi=x_c + r * cos (theta);
  yi=y_c + r * sin (theta);
  glColor3f(0.5,0.5,1);
  glVertex2d(xi,yi);
  }
  glEnd();
//4thcircle
  x_c=200,y_c=250,r=90;
  glBegin(GL_POLYGON);
  for(count=1;count<=10000;count++)
  {
  theta=theta+0.001;
  xi=x_c + r * cos (theta);
  yi=y_c + r * sin (theta);
  glColor3f(0,0,0);
  glVertex2d(xi,yi);
  }
  glEnd();



  //THE POLYGON

  glColor3f(1.0f, 1.0f, 1.0f); // sets color
  glBegin(GL_POLYGON);
  glVertex2i(150, 180); // vertex 1
  glVertex2f(250, 180); // vertex 2
  glVertex2f(250, 315); // vertex 3
  glVertex2f(150, 315); // vertex 4

   glEnd();
   glFlush();
glTranslatef(50,10 ,0);
glEnd();
  //TRIANGLES
  //1
  glBegin(GL_TRIANGLES);
  glColor3f(0,1,0);
   glVertex2i(300,370);
  glVertex2i(300,450);
 glVertex2i(200,450);
  glEnd();
  
//2
  glBegin(GL_TRIANGLES);
  glColor3f(1,1,0);
  glVertex2i(300,10);
  glVertex2i(300,90);
  glVertex2i(170,10);
    
  glEnd();
//3
  glBegin(GL_TRIANGLES);
  glColor3f(.2,1,0.5);
  glVertex2i(10,10);
  glVertex2i(110,10);
  glVertex2i(10,110);
 
glEnd();
//4
  glBegin(GL_TRIANGLES);
  glColor3f(1,1,0);
  glVertex2i(10,370);
  glVertex2i(140,450);
  glVertex2i(10,450);

  glEnd(); 
  glFlush();
}

///////////////////////////////////

void Initial ()
{
 glClearColor(0.0,0.0,0.0,0.0);       // set black background color 
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity(); 
; 
 gluOrtho2D(0,400,0,500);
}

////////the main

int  main()
{ 
 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
 glutInitWindowSize (300,340);
 glutInitWindowPosition (50,50);
 glutCreateWindow("Abeer_Q2");
  Initial();
 glutDisplayFunc(drawShapes);
 glutMainLoop();
return 0;
}  
Last edited on
Topic archived. No new replies allowed.