Open GL: draw rectangles with borders?
11,757
You can draw a rectangle 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 use a state machine. So for changing the color just put :
glColor3f (R, G, B);
before your drawing primitives.
So, mixing it up, your step should be:
- choose fill color
- draw fill rect with glRectf
- choose border color
- draw unfilled rect with the code I posted
These steps repeated for each rectangle you are drawing of course.
Author by
user469652
Updated on June 20, 2022Comments
-
user469652 almost 2 years
Check the image I produced, but what I want to do is producing those rectangles with borders, and set the background colour to another. How can I do that?
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()