简体   繁体   中英

GL-Enabling Texture2D in MonoTouch/OpenTK/GLKit generates error 0x0500

I'm using OpenTK-1.0.dll in MonoTouch 5.2.13 in a GLKViewController. I can render 3D objects using coloured vertices, everything there works fine.

Now I'd like to render 3D objects with texture maps. To accomplish this, I added the following call to my ViewDidLoad method (in my subclass of GLKViewController):

GL.Enable(EnableCap.Texture2D);

But since I added this call, the OpenGL screen stays black (no more coloured vertices), and on the Console I see

GL ERROR: 0x0500

When I remove the GL.Enable call, everything is working again.

Any hints?

glEnable(GL_TEXTURE_2D) (or the openTK equivalent) does not exist in OpenGLES 2.0. It only controls texturing for the fixed pipeline.

To use textures in OpenGLES 2.0, you just sample them in your shader, there's no need to enable anything.

Solved it, I had to add the following:

_baseEffect.Texture2d0.Enabled = true;
_baseEffect.Texture2d0.GLName = _myGlkTexture.Name;
_baseEffect.Texture2d0.EnvMode = GLKTextureEnvMode.Replace;
_baseEffect.Texture2d0.Target = GLKTextureTarget.Texture2D;
_baseEffect.PrepareToDraw();

The BaseEffect class takes care of managing the shaders, so we just have to tell it to activate the texture rendering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM