glDrawArrays在GL_TRIANGLES模式中不绘制任何内容 [英] glDrawArrays does not draw anything in GL_TRIANGLES mode
本文介绍了glDrawArrays在GL_TRIANGLES模式中不绘制任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是 glDrawArray
命令停止工作。我写了一些程序,我使用该命令。但现在,我不知道为什么它不工作。
但我还是可以用 GL_LINES
而不是 GL_TRIANGLES
。
这是我的代码:
#includeMesh.h
#include< iostream>
Mesh :: Mesh()
{
glGenVertexArrays(1,& vao);
glBindVertexArray(vao);
glGenBuffers(1,& vbo);
size = 0;
}
void Mesh :: AddVertices(const Vertex vertices [],int length)
{
size = length;
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW);
}
void Mesh :: Draw()
{
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,Vertex :: SIZE * 4,0);
glDrawArrays(GL_TRIANGLES,0,size);
glDisableVertexAttribArray(0);
}
绘制总是由Game类调用。和我的Vertex类:
#includeVertex.h
Vertex :: Vertex :: vec3 pos)
{
this-> pos = pos;
}
Vertex :: Vertex(float x,float y,float z)
{
pos = glm :: vec3(x,y,z)
}
glm :: vec3 Vertex :: GetPos()const
{
return pos;
}
void Vertex :: SetPos(glm :: vec3 pos)
{
this-> pos = pos;
}
解决方案
。当我初始化我的OpenGL函数时,我不小心写了 glFrontFace(GL_CW)
而不是 glFrontFace(GL_CCW)
p>
My problem is the glDrawArray
command stops working. I've written a few programs which I used that command. However now, I don't have any idea why it doesn't work.
But I still can draw lines to the screen with GL_LINES
instead of GL_TRIANGLES
.
Here is my code:
#include "Mesh.h"
#include <iostream>
Mesh::Mesh()
{
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
size = 0;
}
void Mesh::AddVertices(const Vertex vertices[], int length)
{
size = length;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
}
void Mesh::Draw()
{
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, Vertex::SIZE * 4, 0);
glDrawArrays(GL_TRIANGLES, 0, size);
glDisableVertexAttribArray(0);
}
Draw is always called by Game class. And my Vertex class:
#include "Vertex.h"
Vertex::Vertex(glm::vec3 pos)
{
this->pos = pos;
}
Vertex::Vertex(float x, float y, float z)
{
pos = glm::vec3(x, y, z);
}
glm::vec3 Vertex::GetPos() const
{
return pos;
}
void Vertex::SetPos(glm::vec3 pos)
{
this->pos = pos;
}
解决方案
I've found the solution. When I initialize my OpenGL functions, I have accidentally written glFrontFace(GL_CW)
instead of glFrontFace(GL_CCW)
.
这篇关于glDrawArrays在GL_TRIANGLES模式中不绘制任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文