OpenGL正方形和箭头
OpenGL Squares and Arrows
我正在尝试创建一个正方形,并在其顶部创建一个箭头。它就像一个2D仪表,有点类似。但我不知道如何在正方形顶部创建箭头。
int count = 1;
for (float y = 1; y < 11; y++) {
y1 = y1 - 0.51;
y2 = y2 - 0.51;
float x2 = -2.0;
for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) {
glColor3f(windy[count], 1.0, 0.0);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
count = count + 1;
x2 = x2 + 0.51;
}
}
glutSwapBuffers();
glEnd(); //End the glBegin Function
这就是我想要的。
glBegin(GL_LINE_LOOP);//start drawing a line loop
glVertex3f(-1.0f, 0.0f, 0.0f);//left of window
glVertex3f(0.0f, -1.0f, 0.0f);//bottom of window
glVertex3f(1.0f, 0.0f, 0.0f);//right of window
glVertex3f(0.0f, 1.0f, 0.0f);//top of window
glEnd();//end drawing of line loop
为什么在glEnd()
调用之前交换缓冲区:
int count = 1;
for (float y = 1; y < 11; y++) {
y1 = y1 - 0.51;
y2 = y2 - 0.51;
float x2 = -2.0;
for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) {
glColor3f(windy[count], 1.0, 0.0);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
count = count + 1;
x2 = x2 + 0.51;
}
}
//glutSwapBuffers(); // wrong place
glEnd(); //End the glBegin Function
glutSwapBuffers(); // Must be after draw operation
要在形状的顶部绘制箭头,必须更多:
int count = 1;
for (float y = 1; y < 11; y++) {
y1 = y1 - 0.51;
y2 = y2 - 0.51;
float x2 = -2.0;
for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) {
glColor3f(windy[count], 1.0, 0.0);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
count = count + 1;
x2 = x2 + 0.51;
}
}
//glutSwapBuffers(); // wrong place
glEnd(); //End the glBegin Function
// draw arrow
glBegin(GL_LINE_LOOP);//start drawing a line loop
glVertex3f(-1.0f, 0.0f, 0.0f);//left of window
glVertex3f(0.0f, -1.0f, 0.0f);//bottom of window
glVertex3f(1.0f, 0.0f, 0.0f);//right of window
glVertex3f(0.0f, 1.0f, 0.0f);//top of window
glEnd();//end drawing of line loo
// atlast we can swap our buffers
glutSwapBuffers(); // Must be after draw operation
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 试试完美的正方形,你能给点小费吗
- 了解 GLM- openGL 中的相机转换
- 如何在全屏模式下(在OpenGL中)使背景透明
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- OpenGL大的3D纹理(>2GB)非常慢
- OpenGL绘制三角形而不是正方形
- 在 OpenGL 中旋转一个正方形
- 无法获取索引缓冲区以在 OpenGL 中绘制正方形
- 渲染正方形时的 OpenGL 黑屏
- 如何使用OpenGL在中心的按钮上绘制正方形
- 如何在opengl中绘制屏幕一小部分大小的正方形网格
- 绕Y轴旋转二维正方形,并使用DirectX或openGL以透视投影方式显示
- 在3.2中使用VAO和VBO绘制OpenGL线条和正方形
- OpenGL正方形和箭头
- 使用c++在opengl中创建正方形网格(2D)
- 在OpenGL中用极坐标绘制正方形
- OpenGL -最简单的方法来绘制一个正方形与纹理
- 我可以在用OpenGL旋转正方形后获得它的顶点吗
- 在Opengl中从不同颜色的正方形中绘制矩形