OpenGl 平面绘图
OpenGl Plane Drawing
我正在尝试制作一个接地层。我的点和索引由函数makeplaneverts
和makeplaneindices
正确生成,但不显示接地平面。任何人都可以看到错误吗?
void makePlaneVerts(int dimensions){
num = (dimensions)*(dimensions);
number = num * 3;
PlaneVerts = new GLfloat[number];
int counter = 0;
for (int i = 0; i < dimensions; i++)
{
for (int j = 0; j < dimensions; j++)
{
PlaneVerts[counter++] = (float)j; cout << counter << j<<endl;
PlaneVerts[counter++] = (float)0; cout << counter << 0<<endl;
PlaneVerts[counter++] = (float)i; cout << counter << i<<endl;
}
}
return ;
}
GLushort *Planeindices;
int NumIndices;
void makePlaneIndices(int dimensions) {
NumIndices = (dimensions - 1) * (dimensions - 1) * 2 * 3;
Planeindices = new GLushort[NumIndices];
int count = 0;
for (int row = 0; row < dimensions - 1; row++)
{
for (int col = 0; col < dimensions - 1; col++)
{
Planeindices[count++] = dimensions * row + col;
cout << count << ":" << dimensions * row + col;
Planeindices[count++] = dimensions * row + col + dimensions;
cout << count << ":" << dimensions * row + col + dimensions;
Planeindices[count++] = dimensions * row + col + dimensions + 1;
cout << count << ":" << dimensions * row + col + dimensions + 1 << endl;
Planeindices[count++] = dimensions * row + col;
cout << count << ":" << dimensions * row + col;
Planeindices[count++] = dimensions * row + col + dimensions + 1;
cout << count << ":" << dimensions * row + col + dimensions + 1;
Planeindices[count++] = dimensions * row + col + 1;
cout << count << ":" << dimensions * row + col + 1 << endl;
}
}
return;
}
初始化平面打开 VBO 一个用于顶点 一个用于索引
void initPlane() {
GLuint myBufferID;
glGenBuffers(1, &myBufferID);
glBindBuffer(GL_ARRAY_BUFFER, myBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(PlaneVerts), PlaneVerts, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
GLuint indexBufferID;
glGenBuffers(1, &indexBufferID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Planeindices), Planeindices, GL_STATIC_DRAW);
}
通过将索引与顶点匹配来显示播放
void displayPlane() {
glDrawElements(GL_TRIANGLES, number/3, GL_UNSIGNED_SHORT, 0);
}
你甚至似乎没有变量名称。定义变量时,需要为其命名:
PlaneVerts myVariableName;
如果您不熟悉这个概念,那么您以前可能没有做过太多编程,请退后一步,查看基本的C++教程。
相关文章:
- 在 cpp 中的平面缓冲区中序列化对象
- 将平面阵列重塑为复杂的特征类型
- CGAL:在浏览平面地图时使用类型"标记"
- 平面缓冲区可以利用向量中的 0 吗?还是其他小波比哈尔变换更好?
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 如何找到两个棋盘平面之间的角度?
- GTKMM:拍摄绘图区域的屏幕截图?
- 平面和球体光线追踪之间的交点
- GTKMM:如何将键盘事件附加到绘图区域?
- 从矢量数组制作平面文件
- 从 TS 到C++的平面缓冲区不起作用
- OpenGL:使用实例化绘图与我正在绘制的帧缓冲进行绘制
- 为什么在我释放左键单击后,我的绘图会消失
- 如何防止opengl绘图拉伸到窗口大小?
- QT 无法通过上下文菜单添加新绘图 (QCustomPlot)
- Wxwidgets - 如何添加调整大小事件处理程序以使"X"绘图随窗口调整大小?
- 单击"推送"按钮应使用Qt C++在不同的窗口中显示绘图
- 从 C++ 调用 GNU 绘图,无需用户输入
- 如何在C++中加快平面到打包/交错图形的速度?
- OpenGl 平面绘图