Exemplo n.º 1
0
        public Q3BspFaces(BinaryReader reader, Q3BspDirEntry dirEntry)
        {
            reader.BaseStream.Seek(Convert.ToInt64(dirEntry.offset), SeekOrigin.Begin);

            int cSize = dirEntry.length / Q3BspFace.GetSize();

            faces = new Q3BspFace[cSize];

            for (int i = 0; i < cSize; i++)
            {
                faces[i] = new Q3BspFace(reader);
            }
        }
Exemplo n.º 2
0
        public void Render(Frustum frustum)
        {
            for (int fi = 0; fi < faces.faces.Length; fi++)
            {
                Q3BspFace curFace = faces.faces[fi];
                //int offset = faces.faces[fi].vertexIndx;

                // 1=polygon, 2=patch, 3=mesh, 4=billboard
                if (faces.faces[fi].faceType == 1 || faces.faces[fi].faceType == 3)                // Polygon
                {
                    TextureManager.Get().SetTexture(textures.textures[curFace.textureIndx].strName);
                    Gl.glActiveTextureARB(Gl.GL_TEXTURE0_ARB);

                    if (curFace.lightmapIndx >= 0)
                    {
                        Gl.glActiveTextureARB(Gl.GL_TEXTURE1_ARB);
                        Gl.glEnable(Gl.GL_TEXTURE_2D);
                        Gl.glBindTexture(Gl.GL_TEXTURE_2D, lightmaps.lightmaps[curFace.lightmapIndx].texId);
                    }

                    Gl.glBegin(Gl.GL_TRIANGLES);
                    for (int i = 0; i < curFace.meshNum; i++)
                    {
                        Q3BspVertex vert = vertices.vertices[curFace.vertexIndx + meshVerts.offsets[curFace.meshIndx + i]];

                        Gl.glMultiTexCoord2fARB(Gl.GL_TEXTURE0_ARB, vert.texcoords[0, 0], vert.texcoords[0, 1]);

                        if (curFace.lightmapIndx >= 0)
                        {
                            Gl.glMultiTexCoord2fARB(Gl.GL_TEXTURE1_ARB, vert.texcoords[1, 0], vert.texcoords[1, 1]);
                        }

                        Gl.glColor3ub(vert.color[0], vert.color[1], vert.color[2]);
                        // Quake3 uses different coordinate system
                        Gl.glVertex3f(vert.position[0], vert.position[2], -vert.position[1]);
                    }
                    Gl.glEnd();

                    Gl.glActiveTextureARB(Gl.GL_TEXTURE0_ARB);

                    //ToDo: Get this run in an safe enviroment
                    //Gl.glVertexPointer(3, Gl.GL_FLOAT, Q3BspVertex.GetSize(), vertices.vertices[offset].position);
                    //stride == Q3BspVertex.GetSize()
                    //Gl.glClientActiveTextureARB(Gl.GL_TEXTURE0_ARB);
                    //Gl.glTexCoordPointer(2, Gl.GL_FLOAT, stride, &(vertex[offset].textureCoord));
                    //glClientActiveTextureARB(GL_TEXTURE1_ARB);
                    //glTexCoordPointer(2, GL_FLOAT, stride, &(vertex[offset].lightmapCoord));
                    //Gl.glDrawElements(Gl.GL_TRIANGLES, curFace.vertexNum, Gl.GL_UNSIGNED_INT, meshVerts.offsets[curFace.vertexIndx]);
                }
            }
        }