Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / Drawing Circle with OpenGL

Drawing Circle with OpenGL

August 20, 2021 by James Palmer

It looks like immediately after you draw the circle, you go into the main glut loop, where you’ve set the Draw() function to draw every time through the loop. So it’s probably drawing the circle, then erasing it immediately and drawing the square. You should probably either make DrawCircle() your glutDisplayFunc(), or call DrawCircle() from Draw().

#include
#include
#include
#include
#include
#include
#define window_width 1080
#define window_height 720
void drawFilledSun(){
//static float angle;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0, 0, -10);
int i, x, y;
double radius = 0.30;
//glColor3ub(253, 184, 19);
glColor3ub(255, 0, 0);
double twicePi = 2.0 * 3.142;
x = 0, y = 0;
glBegin(GL_TRIANGLE_FAN); //BEGIN CIRCLE
glVertex2f(x, y); // center of circle
for (i = 0; i <= 20; i++) { glVertex2f ( (x + (radius * cos(i * twicePi / 20))), (y + (radius * sin(i * twicePi / 20))) ); } glEnd(); //END } void DrawCircle(float cx, float cy, float r, int num_segments) { glBegin(GL_LINE_LOOP); for (int ii = 0; ii < num_segments; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component glVertex2f(x + cx, y + cy);//output vertex } glEnd(); } void main_loop_function() { int c; drawFilledSun(); DrawCircle(0, 0, 0.7, 100); glutSwapBuffers(); c = getchar(); } void GL_Setup(int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glEnable(GL_DEPTH_TEST); gluPerspective(45, (float)width / height, .1, 100); glMatrixMode(GL_MODELVIEW); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(window_width, window_height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("GLUT Example!!!"); glutIdleFunc(main_loop_function); GL_Setup(window_width, window_height); glutMainLoop(); } This is what I did. I hope this helps. Two types of circle are here. Filled and unfilled.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in