Open GL: draw rectangles with borders?

enter image description here

Check the image I created, but I want to create rectangles with borders and set the background color to another. How can i do this?

glRectf(top_left_x, top_left_y, bottom_right_x, bottom_right_y)? if loop==0: ratio = 0.10 glBegin(GL_QUADS) while ratio <= 1.0: width = window_width/2 height = window_height long_length = width * ratio short_length = height* (1.0 - ratio) top_left_x = (width - long_length) / 2.0 top_left_y = (height - window_height * (1.0-ratio)) /2 bottom_right_x = top_left_x + long_length bottom_right_y = top_left_y + short_length glColor(1.0,1.0,1.0,0.5) glVertex3f(top_left_x, top_left_y, 0.0) glVertex3f(top_left_x + long_length, top_left_y, 0.0) glVertex3f(bottom_right_x,bottom_right_y, 0.0) glVertex3f(bottom_right_x-long_length,bottom_right_y, 0.0) ratio += 0.05 glEnd() 
+4
source share
1 answer

You can draw a rectangle that is not filled this way:

 glBegin(GL_LINES); glVertex2d(top_left_x, top_left_y); glVertex2d( top_right_x, top_right_y); glVertex2d( bottom_right_x,bottom_right_y); glVertex2d(bottom_left_x,bottom_left_y); glVertex2d(top_left_x, top_left_y); glEnd(); 

OpenGL uses a state machine. So, to change the color just put:

 glColor3f (R, G, B); 

in front of your drawing primitives.

So, mixing it, your step should be:

  • select fill color
  • draw fill rect with glRectf
  • choose border color
  • draw an empty rectangle with the code that I posted

These steps are repeated for every rectangle you draw, of course.

+7
source

Source: https://habr.com/ru/post/1346962/


All Articles