OpenGL正在使用最后加载的纹理
OpenGL is using the last texture loaded
编辑:我将其范围缩小到了:似乎我在函数中执行以下操作,然后在渲染器函数中再也不会调用glbindTexture,它仍然会呈现...纹理...
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
//glGenTextures ( 1 , &NM->texture [ 0 ] ); // ** OFF **
//glBindTexture ( GL_TEXTURE_2D, NM->texture [ 0 ] ); // ** OFF **
//glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ); // ** Enableing This Will Render White (no texture)
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ); // ** Enableing This Will Render the texture for both objects *** SUPER WEIRD ***
// *** ALSO *** I dont ever call glBindTexture Again after this but still the object is being textured ***
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->width , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
我一定不能理解某些东西,或者我的代码中有很大的错误。
我只是想用加载材料并渲染的材料来获取波前对象。话虽如此,我只是想整理一些代码,以更好地了解一切的工作原理,以便我可以返回并重新编程所有内容。(我在Windows上)
i可以从文件甚至加载纹理加载.objects ...问题是,加载的最后一个纹理用于所有对象....
在这里,它可以加载图像...
glGenTextures(1,05331C10)
glBindTexture(GL_TEXTURE_2D,1)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,1024,1024,0,GL_RGBA,GL_UNSIGNED_BYTE,05733040)
glGenTextures(1,05332780)
glBindTexture(GL_TEXTURE_2D,2)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,1024,1024,0,GL_RGBA,GL_UNSIGNED_BYTE,0573D040)
..来自:
NM->MapUsed = true;
sscanf ( coord [ i ]->c_str() , "map_Kd %s" , NM->map_Kd );
char FileBuf [ 256 ] = { 0x0 };
sprintf ( FileBuf , "C:\OpenGL\Debug\%s" , NM->map_Kd );
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
glGenTextures ( 1 , &NM->texture );
glBindTexture ( GL_TEXTURE_2D, NM->texture );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
上面的代码是我加载纹理的方式。NM位于vectormateriallibrary中的向量阵列中,即在Objectloader vector中...
void Renderer() {
updatecam();
// all My Objects
for ( int i = 0 ; i < ObjectLoader.size() ; i++ ) {
sObjectLoader *TempObject = ObjectLoader [ i ];
if ( TempObject->MTLFile ) {
for ( int z = 0 ; z < TempObject->VectorMaterialLibrary.size() ; z++ ) {
sMaterialLibrary *TempMaterial = TempObject->VectorMaterialLibrary [ z ];
if ( strcmp ( TempMaterial->newmtl , TempObject->usemtl ) == 0 ) {
if ( TempMaterial->MapUsed ) {
glBindTexture ( GL_TEXTURE_2D, TempMaterial->texture ); // *** This Dings 1/2 respectively ***
}
break;
}
}
}
for ( int z = 0 ; z < TempObject->_3f.size() ; z++ ) {
s3f *Temp3f = TempObject->_3f [ z ];
if ( Temp3f->GL_TYPE == GL_QUADS ) {
glBegin ( GL_QUADS );
if ( Temp3f->boolvn ) {
glNormal3f ( Temp3f->vn [ 0 ] , Temp3f->vn [ 1 ] , Temp3f->vn [ 2 ] );
}
if ( Temp3f->boolv ) {
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 0 ] , Temp3f->vt [ 1 ] );
glVertex3f ( Temp3f->v [ 0 ] , Temp3f->v [ 1 ] , Temp3f->v [ 2 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 2 ] , Temp3f->vt [ 3 ] );
glVertex3f ( Temp3f->v [ 3 ] , Temp3f->v [ 4 ] , Temp3f->v [ 5 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 4 ] , Temp3f->vt [ 5 ] );
glVertex3f ( Temp3f->v [ 6 ] , Temp3f->v [ 7 ] , Temp3f->v [ 8 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 6 ] , Temp3f->vt [ 7 ] );
glVertex3f ( Temp3f->v [ 9 ] , Temp3f->v [ 10 ] , Temp3f->v [ 11 ] );
}
glEnd();
} else {
glBegin ( GL_TRIANGLES );
if ( Temp3f->boolvn ) {
glNormal3f ( Temp3f->vn [ 0 ] , Temp3f->vn [ 1 ] , Temp3f->vn [ 2 ] );
}
if ( Temp3f->boolv ) {
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 0 ] , Temp3f->vt [ 1 ] );
glVertex3f ( Temp3f->v [ 0 ] , Temp3f->v [ 1 ] , Temp3f->v [ 2 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 2 ] , Temp3f->vt [ 3 ] );
glVertex3f ( Temp3f->v [ 3 ] , Temp3f->v [ 4 ] , Temp3f->v [ 5 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 4 ] , Temp3f->vt [ 5 ] );
glVertex3f ( Temp3f->v [ 6 ] , Temp3f->v [ 7 ] , Temp3f->v [ 8 ] );
}
glEnd();
}
}
}
}
另外,渲染的glintercept(获取最后一个image1调用和Image2的开始...)
glBegin(GL_TRIANGLES) Textures[ (0,1) ]
glNormal3f(0.000000,0.000000,-1.000000)
glTexCoord2f(1.000000,0.000000)
glVertex3f(1.892851,-0.950534,-3.331728)
glTexCoord2f(1.000000,1.000000)
glVertex3f(-0.107149,-0.950534,-3.331728)
glTexCoord2f(0.000000,1.000000)
glVertex3f(-0.107149,1.049466,-3.331728)
glEnd()
glBindTexture(GL_TEXTURE_2D,2)
glBegin(GL_TRIANGLES) Textures[ (0,2) ]
glNormal3f(0.000000,-1.000000,-0.000000)
glTexCoord2f(0.000000,0.000000)
glVertex3f(1.892851,-0.950534,-3.331728)
glTexCoord2f(1.000000,0.000000)
glVertex3f(1.892851,-0.950534,-1.331729)
glTexCoord2f(0.000000,1.000000)
glVertex3f(-0.107149,-0.950534,-3.331728)
glEnd()
我想知道我在哪里做错了。我真的只是希望它能起作用,以便我可以再次从头开始重新编码框架。
如果您需要进一步的代码,我可以发布它,但是我不想要一堵墙!
//编辑,手动执行以下操作.. bad
// I only have 2 objects with this test, and 2 materials...
if ( testing ) {
glGenTextures ( 2 , Gtextures ); // ********Global
testing = false;
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
glBindTexture ( GL_TEXTURE_2D, Gtextures[0] );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
} else {
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
glBindTexture ( GL_TEXTURE_2D, Gtextures[1] );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
}
**
for ( int z = 0 ; z < TempObject->VectorMaterialLibrary.size() ; z++ ) {
sMaterialLibrary *TempMaterial = TempObject->VectorMaterialLibrary [ z ];
if ( strcmp ( TempMaterial->newmtl , TempObject->usemtl ) == 0 ) {
if ( TempMaterial->MapUsed ) {
//mbci ( "Changing Texture" , i );
//mbci ( "Gtextures [ i ]" , Gtextures [ i ] );
glBindTexture ( GL_TEXTURE_2D, Gtextures [ i ] ); // ** I only have 2 objects so this works for loading the 2 textures...
//glBindTexture ( GL_TEXTURE_2D, TempMaterial->texture );
}
break;
}
}
但是对象仍然是相同的纹理...
这是我正在渲染的东西的图片。请注意,所有内容都是相同的颜色...中间的两个立方体应该是两种不同的颜色,而其他对象也采用相同的纹理...这是两个纹理(缩小OFC)
What I See https://i.stack.imgur.com/s1NXn.png ** No Idea **
Cube UV1 https://i.stack.imgur.com/s44Tb.png ** This is loaded first**
Cube UV2 https://i.stack.imgur.com/8KXdo.png ** This is loaded last **
我不愿意这样做,但是经过几天的调试并浏览了我的OpenGL小册子,我回答了自己的问题。
我的代码问题是基于.obj格式以及我如何订购面孔的问题。在.obj格式中,每个.obj是递增的...示例:
对象一个
f 5/1/1 6/2/1 1/3/1
f 6/1/2 7/2/2 2/3/2
f 7/1/3 8/2/3 3/3/3
f 8/1/4 5/2/4 4/3/4
f 1/1/5 2/2/5 4/3/5
f 8/1/6 7/2/6 5/3/6
f 6/2/1 2/4/1 1/3/1
f 7/2/2 3/4/2 2/3/2
f 8/2/3 4/4/3 3/3/3
f 5/2/4 1/4/4 4/3/4
f 2/2/5 3/4/5 4/3/5
f 7/2/6 6/4/6 5/3/6
对象两个
f 9/5/7 10/6/7 12/7/7
f 13/5/8 16/6/8 14/7/8
f 9/5/9 13/6/9 10/7/9
f 10/5/10 14/6/10 11/7/10
f 11/5/11 15/6/11 12/7/11
f 13/5/12 9/6/12 16/7/12
f 10/6/7 11/8/7 12/7/7
f 16/6/8 15/8/8 14/7/8
f 13/6/13 14/8/13 10/7/13
f 14/6/10 15/8/10 11/7/10
f 15/6/11 16/8/11 12/7/11
f 9/6/12 12/8/12 16/7/12
我如何存储顶点/vertextextexture/pertexnormals,是正确的,,但是我的循环从第二个对象上的0开始,这意味着我实际上是在重新创建第一个对象,因此它应用了最后的纹理...
给其他任何人:请注意您的程序如何存储和阅读内容。
几天的工作,只有一行代码更改以使其功能... yippie。
如果有一种方法可以确保搅拌机不这样做,那就太好了...
- 在 OpenGL 中加载纹理C++
- 从文件问题加载纹理 Android NDK 和 OpenGL
- 是什么导致 glTexSubImage1D() - 加载纹理时在此示例中出现GL_INVALID_VALUE错误?
- Directx11 加载纹理
- 如何在单独的线程上加载纹理到主内存并使用它在另一个线程上渲染
- 如何加载纹理Opengl
- DirectX9 C++ - 在窗口最小化时加载纹理
- 渲染时加载纹理 (OpenGL)
- 使用 Openscenegraph 加载纹理时出错
- SDL2和GLFW3:加载纹理;违反访问
- 使用opengl和opencv加载纹理
- 加载纹理无法正常工作的功能
- 仅使用 alpha 值加载纹理
- OpenGL 更改/重新加载纹理
- 在DirectX9/C++中为OBJMesh加载纹理坐标
- OpenGL在没有或有静态设备上下文的情况下加载纹理
- 使用 OpenCV 为 OpenGL 加载纹理
- c++ OpenGL/SDL 2.0加载纹理失败
- 我如何使用FreeImage库加载纹理到OpenGL
- 使用SOILs OGL函数和OpenGL加载纹理