Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open GL: draw rectangles with borders?

Tags:

opengl

enter image description here

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()
like image 629
user469652 Avatar asked Apr 06 '11 18:04

user469652


1 Answers

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:

  1. choose fill color
  2. draw fill rect with glRectf
  3. choose border color
  4. draw unfilled rect with the code I posted

These steps repeated for each rectangle you are drawing of course.

like image 74
Heisenbug Avatar answered Nov 17 '22 16:11

Heisenbug