I really need to draw a bottle shape or something like that in OpenGL.

    1 answer 1

    1. Draw a bottle profile on a piece of paper in a checkered box.
    2. Drop one half (is the bottle symmetrical?).
    3. Break the profile into straight sections with anchor points. In places of strong bending of points, more points are needed, in smooth areas - smaller ones.
    4. Congratulations, you have approximated a curve. Now determine the coordinates of points in a convenient coordinate system (starting at the center of the bottom, for example).
    5. Hammer into the program an array of reference points. Select another array of the same dimension (let's call it temporary), but leave it empty.
    6. Now we will rotate our profile. Select the number of faces at the bottle n . Then the pitch will be 360/n degrees.
    7. Next, take in order the coordinates of 2 neighboring points from the array, rotate them by the above-mentioned angle around the vertical axis, you get 2 new coordinates. Draw a polygon through these 4 points. 2 save the calculated coordinates in a temporary array. Repeat the procedure for all segments. Because in the temporary array will be the results of previous calculations, for all segments except the first one, you only need to calculate by one point. When all segments are processed, swap the temporary and main arrays. New temporary - clear.
    8. Repeat step 7 for all faces from 1 to n.

    If you go deeper, it is better to first obtain the coordinates of all reference vertices in the form of a 2-dimensional array (so as not to recalculate them every time you draw), and then output them in the right place.