//public unsafe GLTexture(GLModel gLModel, MDL0TextureNode tex) //{ // _name = tex.Name; //} public unsafe uint Initialize(GLContext context) { if (_remake) { ClearTexture(context); uint id = 0; context.glGenTextures(1, &id); _texId = id; context.glBindTexture(GLTextureTarget.Texture2D, id); context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureFilter.LINEAR); context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureFilter.NEAREST_MIPMAP_LINEAR); context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0); context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, _textures.Length - 1); for (int i = 0; i < _textures.Length; i++) { Bitmap bmp = _textures[i]; BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); context.glTexImage2D(GLTexImageTarget.Texture2D, i, (GLInternalPixelFormat)4, data.Width, data.Height, 0, GLPixelDataFormat.BGRA, GLPixelDataType.UNSIGNED_BYTE, (void *)data.Scan0); bmp.UnlockBits(data); } _remake = false; ClearImages(); } return(_texId); }
public void Bind() { if (_context != null) { _context.glBindTexture(GLTextureTarget.Texture2D, _id); } }
public void Bind(int index, int program) { if (_context != null) { //if (program != -1) //{ // _context.glUniform1(_context.glGetUniformLocation((uint)program, "samp" + index), index); // _context.glActiveTexture((GLMultiTextureTarget)((int)GLMultiTextureTarget.TEXTURE0 + index)); //} _context.glBindTexture(GLTextureTarget.Texture2D, _id); } }
internal unsafe void Render(GLContext context, uint[] texIds) { if (!_enabled) { return; } //context.glEnable(GLEnableCap.Texture2D); if (_parent._uvData[0] == null) { return; } //Vector3* vPtr = (Vector3*)_parent._vertices.Address; //Vector3* nPtr = _parent._normals != null ? (Vector3*)_parent._normals.Address : null; ARGBPixel *c1Ptr = _parent._colors1 != null ? (ARGBPixel *)_parent._colors1.Address : null; ARGBPixel *c2Ptr = _parent._colors2 != null ? (ARGBPixel *)_parent._colors2.Address : null; //Vector2* uvPtr = _parent._uvData[0] != null ? (Vector2*)_parent._uvData[0].Address : null; int numUV = 0; Vector2 *[] uPtrs = new Vector2 *[8]; while (_parent._uvData[numUV] != null) { uPtrs[numUV] = (Vector2 *)_parent._uvData[numUV].Address; numUV++; } Vector3 v, n; Vector2 u; uint id; fixed(Vector3 *vPtr = _vertices) fixed(Vector3 * nPtr = _normals) { for (int t = 0; t < 1; t++) { if ((id = texIds[t]) == 0) { continue; } context.glBindTexture(GLTextureTarget.Texture2D, id); context.glBegin(_type); for (int i = 0; i < _elements; i++) { if (c1Ptr != null) { context.glColor4((byte *)&c1Ptr[_colorIndices[0][i]]); } //if(c2Ptr != null) // context.glColor4((byte*)&c2Ptr[_colorIndices[1][i]]); context.glNormal((float *)&nPtr[i]); context.glTexCoord2((float *)&uPtrs[0][_uvIndices[0][i]]); //u = uPtrs[t][_uvIndices[t][i]]; //context.glTexCoord2((float*)&u); context.glVertex3v((float *)&vPtr[i]); } context.glEnd(); } } context.CheckErrors(); }