OpenGL, C++ Cornered Box
OpenGL, C++ Cornered Box
我一直在为一个游戏(学校项目(制作GUI菜单,我们已经准备好了引擎模板,只需要制作一个GUI菜单。我和我的朋友在老师的帮助下成功地制作了一个未填充的盒子。这里是功能:
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
因为它看起来好多了,但我和我的朋友已经在这里坐了几天,不知道如何做到这一点。
使用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–a
- 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();
最后,您可以将坐标阵列加载到OpenGL顶点阵列中,并使用glDrawArrays或glDrawElements。
相关文章:
- C++:从盒装元素的向量构造 Box 类型的向量
- 为什么我们选择"bounding box"方法来填充三角形?
- Box muller distribution
- Box Muller Transform在实现正态分布PRNG时的问题
- 我的"out of the box"程序可以在 Windows 中在哪里可靠地创建目录?
- 在Message Box Husing手柄中显示DLL的路径
- 如何以编程方式为应用程序创建文件夹,以使用 BOX REST API 在其中上传内容
- AIX Box 程序中C++跟踪/BPT 陷阱
- 将 Gtk::Grid 重复添加到 Gtk::Box
- 如何在box.get_string()中使用FLTK
- 将文件上传到 box.net
- 启动 VirtualBoxSDK 测试应用程序返回错误"Error creating virtual box instance"
- BlackBerry 10 - Dialog Box
- C++中的Box滤波算法
- CLI / c++.如何使用存储在变量中的名称来引用box
- 使用box.net, dropbox,(或任何云存储)与一个c++应用程序
- 类模板 - 从"box"对象中删除项
- Linux护士覆盖由box()创建的边界
- OpenGL, C++ Cornered Box
- 如何在C++中创建带有用户定义按钮的MESSAGE BOX