2011-04-06 192 views
4

enter image description hereOpen GL:繪製帶邊框的矩形?

檢查我生成的圖像,但我想要做的是生成帶有邊框的矩形,並將背景顏色設置爲另一個。我怎樣才能做到這一點?

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() 

回答

7

可以繪製未填寫這樣一個矩形:

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的使用狀態機。所以對於改變顏色只是把:

glColor3f (R, G, B); 

之前你的繪製原語。

因此,混合起來,你的步驟應該是:

  1. 選擇填充顏色
  2. 平局填充矩形與glRectf
  3. 選擇邊框顏色
  4. 戰平我張貼
  5. 代碼填充矩形

這些步驟重複您正在繪製每個矩形當然。

+0

我改變了你的提供,但我得到完全相同的圖像。還有更多問題嗎? – user469652 2011-04-06 19:07:04

+0

@ user469652:你還沒有發佈任何代碼。用那條線我不能告訴你更多。 – Heisenbug 2011-04-06 19:07:56

+0

我粘貼了我的代碼,非常感謝您的幫助。 – user469652 2011-04-06 19:11:26