Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenGL Vertexbuffer对象纹理坐标 我想用VBO在C++中创建网格类。 该类如下所示: mesh::mesh(std::vector<Vector3d>* Vertices, std::vector<unsigned int>* Indices, std::vector<Vector2d>* TextureCoords) { if(Vertices) this->vertices = *Vertices; if(Indices) this->indices = *Indices; if(TextureCoords) this->textureCoords = *TextureCoords; chatbox.AddMessageToQueue("vertices.size() : %d", vertices.size()); glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(Vector3d) + textureCoords.size()*sizeof(Vector2d), 0, GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size()*sizeof(Vector3d), vertices.data()); glBufferSubData(GL_ARRAY_BUFFER, vertices.size()*sizeof(Vector3d), textureCoords.size()*sizeof(Vector2d), textureCoords.data()); glGenBuffers(1, &IND); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IND); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(unsigned int), &indices[0], GL_STATIC_DRAW); } void mesh::draw() { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, VBO); glVertexPointer(3, GL_FLOAT, 0, (void*)0); glTexCoordPointer(2, GL_FLOAT, 0, (void*)(sizeof(float)*3*6)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IND); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, (unsigned int*)0 + 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } mesh::mesh(std::vector*顶点,std::vector*索引,std::vector*纹理词){ 如果(顶点)此->顶点=*顶点; 如果(索引)此->索引=*索引; 如果(TextureCoords)此->TextureCoords=*TextureCoords; AddMessageToQueue(“顶点.size():%d”,顶点.size()); glGenBuffers(1,&VBO); glBindBuffer(GL_数组_BUFFER,VBO); glBufferData(GL_数组_BUFFER,顶点.size()*sizeof(Vector3d)+textureCoords.size()*sizeof(Vector2d),0,GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER,0,顶点.size()*sizeof(Vector3d),顶点.data()); glBufferSubData(GL_ARRAY_BUFFER,顶点.size()*sizeof(Vector3d),textureCoords.size()*sizeof(Vector2d),textureCoords.data()); glGenBuffers(1,&IND); glBindBuffer(GL_元素_数组_缓冲区,IND); glBufferData(GL\u元素\u数组\u缓冲区,index.size()*sizeof(unsigned int),&index[0],GL\u静态\u绘图); } void mesh::draw(){ glEnableClientState(GL_顶点_数组); glEnableClientState(GL_纹理_坐标_阵列); glBindBuffer(GL_数组_BUFFER,VBO); glVertexPointer(3,GL_FLOAT,0,(void*)0); glTexCoordPointer(2,GL_FLOAT,0,(void*)(sizeof(FLOAT)*3*6)); glBindBuffer(GL_元素_数组_缓冲区,IND); glpaurements(GL_三角形,index.size(),GL_UNSIGNED_INT,(UNSIGNED INT*)0+0); glDisableClientState(GL_顶点_数组); glDisableClientState(GL_纹理_坐标_数组); }_C++_Opengl_Textures_Vbo - Fatal编程技术网 顶点=*顶点; 如果(索引)此->索引=*索引; 如果(TextureCoords)此->TextureCoords=*TextureCoords; AddMessageToQueue(“顶点.size():%d”,顶点.size()); glGenBuffers(1,&VBO); glBindBuffer(GL_数组_BUFFER,VBO); glBufferData(GL_数组_BUFFER,顶点.size()*sizeof(Vector3d)+textureCoords.size()*sizeof(Vector2d),0,GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER,0,顶点.size()*sizeof(Vector3d),顶点.data()); glBufferSubData(GL_ARRAY_BUFFER,顶点.size()*sizeof(Vector3d),textureCoords.size()*sizeof(Vector2d),textureCoords.data()); glGenBuffers(1,&IND); glBindBuffer(GL_元素_数组_缓冲区,IND); glBufferData(GL\u元素\u数组\u缓冲区,index.size()*sizeof(unsigned int),&index[0],GL\u静态\u绘图); } void mesh::draw(){ glEnableClientState(GL_顶点_数组); glEnableClientState(GL_纹理_坐标_阵列); glBindBuffer(GL_数组_BUFFER,VBO); glVertexPointer(3,GL_FLOAT,0,(void*)0); glTexCoordPointer(2,GL_FLOAT,0,(void*)(sizeof(FLOAT)*3*6)); glBindBuffer(GL_元素_数组_缓冲区,IND); glpaurements(GL_三角形,index.size(),GL_UNSIGNED_INT,(UNSIGNED INT*)0+0); glDisableClientState(GL_顶点_数组); glDisableClientState(GL_纹理_坐标_数组); },c++,opengl,textures,vbo,C++,Opengl,Textures,Vbo" /> 顶点=*顶点; 如果(索引)此->索引=*索引; 如果(TextureCoords)此->TextureCoords=*TextureCoords; AddMessageToQueue(“顶点.size():%d”,顶点.size()); glGenBuffers(1,&VBO); glBindBuffer(GL_数组_BUFFER,VBO); glBufferData(GL_数组_BUFFER,顶点.size()*sizeof(Vector3d)+textureCoords.size()*sizeof(Vector2d),0,GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER,0,顶点.size()*sizeof(Vector3d),顶点.data()); glBufferSubData(GL_ARRAY_BUFFER,顶点.size()*sizeof(Vector3d),textureCoords.size()*sizeof(Vector2d),textureCoords.data()); glGenBuffers(1,&IND); glBindBuffer(GL_元素_数组_缓冲区,IND); glBufferData(GL\u元素\u数组\u缓冲区,index.size()*sizeof(unsigned int),&index[0],GL\u静态\u绘图); } void mesh::draw(){ glEnableClientState(GL_顶点_数组); glEnableClientState(GL_纹理_坐标_阵列); glBindBuffer(GL_数组_BUFFER,VBO); glVertexPointer(3,GL_FLOAT,0,(void*)0); glTexCoordPointer(2,GL_FLOAT,0,(void*)(sizeof(FLOAT)*3*6)); glBindBuffer(GL_元素_数组_缓冲区,IND); glpaurements(GL_三角形,index.size(),GL_UNSIGNED_INT,(UNSIGNED INT*)0+0); glDisableClientState(GL_顶点_数组); glDisableClientState(GL_纹理_坐标_数组); },c++,opengl,textures,vbo,C++,Opengl,Textures,Vbo" />

OpenGL Vertexbuffer对象纹理坐标 我想用VBO在C++中创建网格类。 该类如下所示: mesh::mesh(std::vector<Vector3d>* Vertices, std::vector<unsigned int>* Indices, std::vector<Vector2d>* TextureCoords) { if(Vertices) this->vertices = *Vertices; if(Indices) this->indices = *Indices; if(TextureCoords) this->textureCoords = *TextureCoords; chatbox.AddMessageToQueue("vertices.size() : %d", vertices.size()); glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(Vector3d) + textureCoords.size()*sizeof(Vector2d), 0, GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size()*sizeof(Vector3d), vertices.data()); glBufferSubData(GL_ARRAY_BUFFER, vertices.size()*sizeof(Vector3d), textureCoords.size()*sizeof(Vector2d), textureCoords.data()); glGenBuffers(1, &IND); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IND); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(unsigned int), &indices[0], GL_STATIC_DRAW); } void mesh::draw() { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, VBO); glVertexPointer(3, GL_FLOAT, 0, (void*)0); glTexCoordPointer(2, GL_FLOAT, 0, (void*)(sizeof(float)*3*6)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IND); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, (unsigned int*)0 + 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } mesh::mesh(std::vector*顶点,std::vector*索引,std::vector*纹理词){ 如果(顶点)此->顶点=*顶点; 如果(索引)此->索引=*索引; 如果(TextureCoords)此->TextureCoords=*TextureCoords; AddMessageToQueue(“顶点.size():%d”,顶点.size()); glGenBuffers(1,&VBO); glBindBuffer(GL_数组_BUFFER,VBO); glBufferData(GL_数组_BUFFER,顶点.size()*sizeof(Vector3d)+textureCoords.size()*sizeof(Vector2d),0,GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER,0,顶点.size()*sizeof(Vector3d),顶点.data()); glBufferSubData(GL_ARRAY_BUFFER,顶点.size()*sizeof(Vector3d),textureCoords.size()*sizeof(Vector2d),textureCoords.data()); glGenBuffers(1,&IND); glBindBuffer(GL_元素_数组_缓冲区,IND); glBufferData(GL\u元素\u数组\u缓冲区,index.size()*sizeof(unsigned int),&index[0],GL\u静态\u绘图); } void mesh::draw(){ glEnableClientState(GL_顶点_数组); glEnableClientState(GL_纹理_坐标_阵列); glBindBuffer(GL_数组_BUFFER,VBO); glVertexPointer(3,GL_FLOAT,0,(void*)0); glTexCoordPointer(2,GL_FLOAT,0,(void*)(sizeof(FLOAT)*3*6)); glBindBuffer(GL_元素_数组_缓冲区,IND); glpaurements(GL_三角形,index.size(),GL_UNSIGNED_INT,(UNSIGNED INT*)0+0); glDisableClientState(GL_顶点_数组); glDisableClientState(GL_纹理_坐标_数组); }

OpenGL Vertexbuffer对象纹理坐标 我想用VBO在C++中创建网格类。 该类如下所示: mesh::mesh(std::vector<Vector3d>* Vertices, std::vector<unsigned int>* Indices, std::vector<Vector2d>* TextureCoords) { if(Vertices) this->vertices = *Vertices; if(Indices) this->indices = *Indices; if(TextureCoords) this->textureCoords = *TextureCoords; chatbox.AddMessageToQueue("vertices.size() : %d", vertices.size()); glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(Vector3d) + textureCoords.size()*sizeof(Vector2d), 0, GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size()*sizeof(Vector3d), vertices.data()); glBufferSubData(GL_ARRAY_BUFFER, vertices.size()*sizeof(Vector3d), textureCoords.size()*sizeof(Vector2d), textureCoords.data()); glGenBuffers(1, &IND); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IND); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(unsigned int), &indices[0], GL_STATIC_DRAW); } void mesh::draw() { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, VBO); glVertexPointer(3, GL_FLOAT, 0, (void*)0); glTexCoordPointer(2, GL_FLOAT, 0, (void*)(sizeof(float)*3*6)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IND); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, (unsigned int*)0 + 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } mesh::mesh(std::vector*顶点,std::vector*索引,std::vector*纹理词){ 如果(顶点)此->顶点=*顶点; 如果(索引)此->索引=*索引; 如果(TextureCoords)此->TextureCoords=*TextureCoords; AddMessageToQueue(“顶点.size():%d”,顶点.size()); glGenBuffers(1,&VBO); glBindBuffer(GL_数组_BUFFER,VBO); glBufferData(GL_数组_BUFFER,顶点.size()*sizeof(Vector3d)+textureCoords.size()*sizeof(Vector2d),0,GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER,0,顶点.size()*sizeof(Vector3d),顶点.data()); glBufferSubData(GL_ARRAY_BUFFER,顶点.size()*sizeof(Vector3d),textureCoords.size()*sizeof(Vector2d),textureCoords.data()); glGenBuffers(1,&IND); glBindBuffer(GL_元素_数组_缓冲区,IND); glBufferData(GL\u元素\u数组\u缓冲区,index.size()*sizeof(unsigned int),&index[0],GL\u静态\u绘图); } void mesh::draw(){ glEnableClientState(GL_顶点_数组); glEnableClientState(GL_纹理_坐标_阵列); glBindBuffer(GL_数组_BUFFER,VBO); glVertexPointer(3,GL_FLOAT,0,(void*)0); glTexCoordPointer(2,GL_FLOAT,0,(void*)(sizeof(FLOAT)*3*6)); glBindBuffer(GL_元素_数组_缓冲区,IND); glpaurements(GL_三角形,index.size(),GL_UNSIGNED_INT,(UNSIGNED INT*)0+0); glDisableClientState(GL_顶点_数组); glDisableClientState(GL_纹理_坐标_数组); },c++,opengl,textures,vbo,C++,Opengl,Textures,Vbo,问题只存在于纹理坐标中。我正在尝试创建网格,如下所示: std::vector<unsigned int> indices; std::vector<mesh::Vector3d> vertices; std::vector<mesh::Vector2d> texCoords; vertices.push_back({PosX, PosY, 1.0}); vertices.push_back({PosX + SizeX, PosY, 1.0}); verti

问题只存在于纹理坐标中。我正在尝试创建网格,如下所示:

std::vector<unsigned int> indices;
std::vector<mesh::Vector3d> vertices;
std::vector<mesh::Vector2d> texCoords;

vertices.push_back({PosX, PosY, 1.0});
vertices.push_back({PosX + SizeX, PosY, 1.0});
vertices.push_back({PosX + SizeX, PosY + SizeY, 1.0});
vertices.push_back({PosX, PosY + SizeY, 1.0});

indices.push_back(0);
indices.push_back(1);
indices.push_back(2);

indices.push_back(0);
indices.push_back(2);
indices.push_back(3);

texCoords.push_back({0, 1});
texCoords.push_back({1, 0});
texCoords.push_back({0, 0});

texCoords.push_back({0, 1});
texCoords.push_back({1, 1});
texCoords.push_back({1, 0});

gui_checkbox = new mesh(&vertices, &indices, &texCoords);
std::向量索引;
向量顶点;
std::向量texCoords;
顶点。向后推_({PosX,PosY,1.0});
顶点。推回({PosX+SizeX,PosY,1.0});
顶点。推回({PosX+SizeX,PosY+SizeY,1.0});
顶点。推回({PosX,PosY+SizeY,1.0});
指数。推回(0);
指数。推回(1);
指数。推回(2);
指数。推回(0);
指数。推回(2);
指数。推回(3);
texCoords.push_back({0,1});
texCoords.push_back({1,0});
texCoords.push_back({0,0});
texCoords.push_back({0,1});
texCoords.push_back({1,1});
texCoords.push_back({1,0});
gui_复选框=新网格(&顶点、&索引和纹理坐标);
但是结果是错误的,正如您在下面的左图中所看到的(右图是所需的):


顶点处于正交模式,因此顶点的坐标原点位于左上角,而纹理坐标的原点位于左下角,就像在OpenGL中一样。

当使用索引来确定顶点位置时,纹理坐标也会被索引。在您的情况下,这意味着您只使用texCoords中的前四个条目。奇怪的外观来自texCoords[0]==texCoords[3]

正确的texCoords很可能是

texCoords.push_back({0, 1});
texCoords.push_back({1, 1});
texCoords.push_back({1, 0});
texCoords.push_back({0, 0});
这些可以从顶点坐标中导出:只要texCoords对应的顶点具有相同的组件值,texCoords在组件上就应该具有相同的值。e、 g.如果顶点[0]。y==顶点[1]。y=>texCoords[0]。y==texCoords[1]。y等等。此外,必须翻转texCoords y坐标,因为顶点原点位于左上角,而texCoords从左下角开始

编辑:

在我看来不正确。此语句说明第一个纹理坐标在第六个矢量3之后开始,但它们不应该在第四个矢量之后开始吗?(顶点中只有4个条目):


当使用索引处理顶点位置时,纹理坐标也会被索引。在您的情况下,这意味着您只使用texCoords中的前四个条目。奇怪的外观来自texCoords[0]==texCoords[3]

正确的texCoords很可能是

texCoords.push_back({0, 1});
texCoords.push_back({1, 1});
texCoords.push_back({1, 0});
texCoords.push_back({0, 0});
这些可以从顶点坐标中导出:只要texCoords对应的顶点具有相同的组件值,texCoords在组件上就应该具有相同的值。e、 g.如果顶点[0]。y==顶点[1]。y=>texCoords[0]。y==texCoords[1]。y等等。此外,必须翻转texCoords y坐标,因为顶点原点位于左上角,而texCoords从左下角开始

编辑:

在我看来不正确。此语句说明第一个纹理坐标在第六个矢量3之后开始,但它们不应该在第四个矢量之后开始吗?(顶点中只有4个条目):


所以我只需要4个纹理坐标而不是6个?即使我使用
GL_三角形
?我也试过使用4个纹理坐标,但也不起作用。是的,你只需要4个纹理坐标。我在回答中添加了我对正确版本的建议。我也尝试过使用4个tex coords,但不起作用,所以我将6个tex coords放回原处。我认为主要问题在于VBO类….+1,尽管还有第二个问题。用于查找纹理数据的偏移错误。它试图通过6个顶点,但缓冲区中只有4个。我现在无法编译,所以我将它发送给我的朋友,他现在尝试了所有编辑,但它不起作用:/90分钟后我将在家,因此我将尝试并发回帖子。他告诉我,纹理现在水平拉伸。所以我只需要4个纹理坐标,而不是6个?即使我使用
GL_三角形
?我也试过使用4个纹理坐标,但也不起作用。是的,你只需要4个纹理坐标。我在回答中添加了我对正确版本的建议。我也尝试过使用4个tex coords,但不起作用,所以我将6个tex coords放回原处。我认为主要问题在于VBO类….+1,尽管还有第二个问题。用于查找纹理数据的偏移错误。它试图通过6个顶点,但缓冲区中只有4个。我现在无法编译,所以我将它发送给我的朋友,他现在尝试了所有编辑,但它不起作用:/90分钟后我将在家,因此我将尝试并发回帖子。他说
glTexCoordPointer(2, GL_FLOAT, 0, (void*)(sizeof(float)*3*4));