2015-07-05 22 views
-1

我一直在为一个游戏(学校项目)的GUI菜单工作,我们有一个引擎模板准备就绪,我们只需要制作一个GUI菜单。我和我的朋友和老师的帮助已经设法使这里充满箱非的功能是:OpenGL,C++角色框

void BoxTest(float x, float y, float width, float height, float Width, Color color) 
{ 
glLineWidth(3); 
glBegin(GL_LINE_LOOP); 
glColor4f(0, 0, 0, 1); 
glVertex2f(x, y); 
glVertex2f(x, y + height); 
glVertex2f(x + width, y + height); 
glVertex2f(x + width, y); 
glEnd(); 
glLineWidth(1); 
glBegin(GL_LINE_LOOP); 
glColor4f(color.r, color.g, color.b, color.a); 
glVertex2f(x, y); 
glVertex2f(x, y + height); 
glVertex2f(x + width, y + height); 
glVertex2f(x + width, y); 
glEnd(); 
} 

这是怎么看起来像现在: http://gyazo.com/c9859e9a8e044e1981b3fe678f4fc9ab

问题是我希望它看起来像这个: http://gyazo.com/0499dd8324d24d63a54225bd3f28463d

打扰它看起来好多了,但我和我的朋友一直坐在这里几天没有线索如何实现这一点。

+0

谢谢,意外链接错误的图片修复了! – StreY

回答

2

对于OpenGL线性原语,您必须将其分解为多行。 GL_LINE_LOOP制作一系列相互连接并在最后关闭的线条。不是你想要的。相反,你应该使用简单的GL_LINES。每两个glVertex调用(顺便说一句:你不应该使用这些,因为glVertex已经过时了;近20年来已经过时了)制作一行。

让我们看看这个ASCII艺术:

0 --- 1 4 --- 3 
|    | 
2    5 

8    b 
|    | 
6 --- 7 a --- 9 

你会画线段

  • 0 - 1
  • 0 - 2
  • 3 - 4
  • 3 - 5
  • 6 - 7
  • 6 - 8
  • 9 - 一个
  • 9 - B

与各点的坐标替换符号0 ... B和可以让这个

glBegin(GL_LINES); 

glVertex(coords[0]); 
glVertex(coords[1]); 
glVertex(coords[0]); 
glVertex(coords[2]); 

glVertex(coords[3]); 
glVertex(coords[4]); 
glVertex(coords[3]); 
glVertex(coords[5]); 

glVertex(coords[6]); 
glVertex(coords[7]); 
glVertex(coords[6]); 
glVertex(coords[8]); 

glVertex(coords[9]); 
glVertex(coords[0xa]); 
glVertex(coords[9]); 
glVertex(coords[0xb]); 

glEnd(); 

作为最后一个触摸你可以将coords数组加载到OpenGL顶点数组中,而是使用glDrawArrays或glDrawElements。