# (flower blooming) done...code inside

This topic is 955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi everybody, i am thinking of drawing a closed flower of 3 ellipses, then rotate the ellipses , and then scale the elipses (to show that it is blooming) here is a picture of what i have in mind, of course it will be in 2D first, any idea of how to draw the ellipse? i studied algorithms of doing that, but the code will be long and have many loops, is there a function to draw an ellipse or even a circle??? function or header file (library) or an easy way?? im working on c++ and just tell me, is it gonna be difficult for a beginner like me to do it?? [Edited by - love247 on July 29, 2007 7:50:18 AM]

##### Share on other sites
Which compiler are you using? at the mo i mite not be much help as i cant get anything under the sun to work in VS but if you are going to do it in openGL i might be able to help, i would recommend for something like this to do it in flash or another animating program but if your doing it as a practice for openGL then i would do a circle, or settle for a rather jagged elipse as curved stuff is kinda advanced its not even mentioned in my openGL book till chapter 14.

if your happy with a circle you could use a quadratic (still chapter 13 stuff) as this is relatively easy but not the most efficient!

second if your happy with jagged just use something like
glBegin(GL_POLYGON);
glVertex2f(0.0f,0.0f)
.....
glEnd();
this is the basic way of drawing something in OpenGL with basic primatives like GL_LINE,GL_QUAD,GL_TRIANGLE,GL_QUAD_STRIP and so on, these are good things to experiment with if you want to go this route ill give you a full list of primatives and rules behind them. the vertex line states one point of that primative shape so you would have to add many points to form a shape, the more points you add the smoother you can make it look, which is why you get algorithms to work out the vertexes for you and make something as smooth as say a elipse

the final way, and probably the best way is to use the inbuilt stuff to represent curves and things, unforntunately i wouldnt be able to help much with that as i dont know much about it myself and as i cant even get VS going at the minute i couldnt test it for you, however i could give you whatever help i can, reading directly from by text book :-)

Hope this helps! (note im still a OpenGL noob myself but i have been using it for a year now)

##### Share on other sites
well, i can use opengl, im not that beginner, but i was wondering about an easy code to draw an ellipse, can you give me one? i searched the websites, but i could not find.. please? :)

##### Share on other sites
Googling "draw ellipse opengl" brings up the answer...

Or, you could draw a circle (also very easily googled) and scale one axis.

##### Share on other sites
as i say im not an expert myself, i would probably go with a circle and use:

//in render loop...

glPushMatrix();
gluDisk(Circle, 0.0,0.5,32,4)
glPopMatrix();

that function in order is:
slices and loops are to do with quality, mess around with them to see what you like.

There is also a gluPartialDisk(..same as above, start Angle, sweep angle) which is mentioned in my book, 2 of them next to each other may provide a useful petal shape? quote from book "sweep angle is how many degrees they arc extends from start angle - that is, the arc ends at start angle + sweep angle. thus, with a start angle of 90 and a sweep angle of 90, an arc would be drawn beginning along the positive x axis and rotating clockwise to the negative z axis"
ive never used it before myself but that sounds like it might be useful!

there is also another method with a bezier curve that might help, it creates a curved line, however this would mean your flower would be outline only? im not sure, ive not used this myself either and would have to look at in a bit more detail for you, tell me which interests you the most and ill look into it for you!

##### Share on other sites
Quote:
 Original post by FunkapotamusGoogling "draw ellipse opengl" brings up the answer...Or, you could draw a circle (also very easily googled) and scale one axis.

scaling the circle is a very good idea actually!...y didnt i think of that!
so you could in theory use the quadtratic code above to draw a circle and just before the function use
glScalef(2,1,2) for example!
saying that though there is almost undoubtly easier and more efficent ways of drawing circles im just not sure what they are!

##### Share on other sites
im sorry, but i tried the GLUquadricObj , there are errors:

'GLUquadricObj' : illegal use of this type as an expression
'Circle' : undeclared identifier

what is the problem?

i google everyhing before i ask here, but i really did not find!!

##### Share on other sites
were did you put the GLUquadricObj *Circle?
try changing circle to another name like FlowerPetal, can you post the code?

##### Share on other sites
Did you forget to #include glu.h by any chance, I'm pretty sure that would cause those errors.

##### Share on other sites
ok ive finally got my VS going and i thought it would be a good experiment to make your project program, i just finished it, its a bit rough around the edges but its done, make sure you include:

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#pragma comment( lib, "opengl32.lib" )
#pragma comment( lib, "glu32.lib" )
#pragma comment( lib, "glaux.lib" )

all there just in case
then declare something like:

for(int count = 0; count < MAX_PETALS; count++)
{
}
then in your draw/render function something along the lines of

for(int count = 0; count < MAX_PETALS; count++)
{
glPushMatrix();
....
glScalef(1,2,1);
gluDisk(g_Petal[count],0.0f,0.5,32,4);
glPopMatrix();
}

theres obv some extra code to rotate the other petals and stuff, all i did was have a switch statement inside the loop that changed the angle depending on the count, and that angle was multiplyed by a bloom factor that started at 0 and moved up to 1.

Good Luck :-)

##### Share on other sites

This topic is 955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013158
×