我已经开始了一个新项目,我想在其中使用多重纹理.
我以前做过multixexturing,并且得到了我的OpenGL版本的支持
在标题中我有:
GLuint m_TerrainTexture[3];//heightmap, texture map and detail map
GLuint m_SkyboxTexture[5]; //left, front, right, back and top textures
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;
PFNGLACTIVETEXTUREARBPROC glActiveTexture;
在构造函数中我有:
glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress((LPCSTR)"glActiveTextureARB");
glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress((LPCSTR)"glMultiTexCoord2fARB");
if(!glActiveTexture || !glMultiTexCoord2fARB)
{
MessageBox(NULL, "multitexturing failed", "OGL_D3D Error", MB_OK);
}
glActiveTexture( GL_TEXTURE0_ARB );
...
这显示消息框“multitexturing failed”,glActiveTexture的内容为0x00000000
当它到达glActiveTexture(GL_TEXTURE0_ARB);我收到访问冲突错误
我正在实现MVC图,所以这都在我的terrain视图类中
最佳答案 您引用了代码来加载扩展,如下所示:
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;
PFNGLACTIVETEXTUREARBPROC glActiveTexture;
glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress((LPCSTR)"glActiveTextureARB");
glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress((LPCSTR)"glMultiTexCoord2fARB");
这是非常有问题的,因为它可能重新定义已经存在的符号. (动态)链接器最终会跳过这个.例如,可能会发生对指针变量glActiveTexture的赋值进入某个地方,但每当调用同名函数时,它会调用从其他地方链接的内容.
在C中,您通常使用预处理器宏和自定义前缀的组合来避免此问题,而无需调整大部分代码.
PFNGLMULTITEXCOORD2FARBPROC myglMultiTexCoord2fARB;
#define glMultiTexCoord2fARB myglMultiTexCoord2fARB
PFNGLACTIVETEXTUREARBPROC myglActiveTexture;
#define glActiveTexture myglActiveTexture
glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress((LPCSTR)"glActiveTextureARB");
glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress((LPCSTR)"glMultiTexCoord2fARB");
如果你有一个有效的渲染上下文并支持扩展,我真的不知道为什么事情会失败的任何其他原因.