public static SetTextureFilters ( TextureMinFilter min, TextureMagFilter mag ) : void | ||
min | TextureMinFilter | |
mag | TextureMagFilter | |
Результат | void |
// R_InitParticleTexture static void InitParticleTexture() { _ParticleTexture = Drawer.GenerateTextureNumber();// texture_extension_number++; Drawer.Bind(_ParticleTexture); byte[,,] data = new byte[8, 8, 4]; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { data[y, x, 0] = 255; data[y, x, 1] = 255; data[y, x, 2] = 255; data[y, x, 3] = (byte)(_DotTexture[x, y] * 255); } } GL.TexImage2D(TextureTarget.Texture2D, 0, Drawer.AlphaFormat, 8, 8, 0, PixelFormat.Rgba, PixelType.UnsignedByte, data); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate); Drawer.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear); }
/// <summary> /// GL_Init /// </summary> private static void InitOpenGL() { _glVendor = GL.GetString(StringName.Vendor); Con.Print("GL_VENDOR: {0}\n", _glVendor); _glRenderer = GL.GetString(StringName.Renderer); Con.Print("GL_RENDERER: {0}\n", _glRenderer); _glVersion = GL.GetString(StringName.Version); Con.Print("GL_VERSION: {0}\n", _glVersion); _glExtensions = GL.GetString(StringName.Extensions); Con.Print("GL_EXTENSIONS: {0}\n", _glExtensions); if (_glRenderer.StartsWith("PowerVR", StringComparison.InvariantCultureIgnoreCase)) { Scr.FullSbarDraw = true; } if (_glRenderer.StartsWith("Permedia", StringComparison.InvariantCultureIgnoreCase)) { Scr.IsPermedia = true; } CheckTextureExtensions(); CheckMultiTextureExtensions(); GL.ClearColor(1, 0, 0, 0); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0.666f); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.ShadeModel(ShadingModel.Flat); Drawer.SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Replace); }
private static byte[] _LightMaps = new byte[4 * MAX_LIGHTMAPS * BLOCK_WIDTH * BLOCK_HEIGHT]; // lightmaps /// <summary> /// GL_BuildLightmaps /// Builds the lightmap texture with all the surfaces from all brush models /// </summary> private static void BuildLightMaps() { Array.Clear(_Allocated, 0, _Allocated.Length); //memset (allocated, 0, sizeof(allocated)); _FrameCount = 1; // no dlightcache if (_LightMapTextures == 0) { _LightMapTextures = Drawer.GenerateTextureNumberRange(MAX_LIGHTMAPS); } Drawer.LightMapFormat = PixelFormat.Luminance;// GL_LUMINANCE; // default differently on the Permedia if (Scr.IsPermedia) { Drawer.LightMapFormat = PixelFormat.Rgba; } if (common.HasParam("-lm_1")) { Drawer.LightMapFormat = PixelFormat.Luminance; } if (common.HasParam("-lm_a")) { Drawer.LightMapFormat = PixelFormat.Alpha; } //if (Common.HasParam("-lm_i")) // Drawer.LightMapFormat = PixelFormat.Intensity; //if (Common.HasParam("-lm_2")) // Drawer.LightMapFormat = PixelFormat.Rgba4; if (common.HasParam("-lm_4")) { Drawer.LightMapFormat = PixelFormat.Rgba; } switch (Drawer.LightMapFormat) { case PixelFormat.Rgba: _LightMapBytes = 4; break; //case PixelFormat.Rgba4: //_LightMapBytes = 2; //break; case PixelFormat.Luminance: //case PixelFormat.Intensity: case PixelFormat.Alpha: _LightMapBytes = 1; break; } for (int j = 1; j < QDef.MAX_MODELS; j++) { model_t m = client.cl.model_precache[j]; if (m == null) { break; } if (m.name != null && m.name.StartsWith("*")) { continue; } _CurrentVertBase = m.vertexes; _CurrentModel = m; for (int i = 0; i < m.numsurfaces; i++) { CreateSurfaceLightmap(m.surfaces[i]); if ((m.surfaces[i].flags & Surf.SURF_DRAWTURB) != 0) { continue; } if ((m.surfaces[i].flags & Surf.SURF_DRAWSKY) != 0) { continue; } BuildSurfaceDisplayList(m.surfaces[i]); } } if (_glTexSort.Value == 0) { Drawer.SelectTexture(MTexTarget.TEXTURE1_SGIS); } // // upload all lightmaps that were filled // GCHandle handle = GCHandle.Alloc(_LightMaps, GCHandleType.Pinned); try { IntPtr ptr = handle.AddrOfPinnedObject(); long lmAddr = ptr.ToInt64(); for (int i = 0; i < MAX_LIGHTMAPS; i++) { if (_Allocated[i, 0] == 0) { break; // no more used } _LightMapModified[i] = false; _LightMapRectChange[i].l = BLOCK_WIDTH; _LightMapRectChange[i].t = BLOCK_HEIGHT; _LightMapRectChange[i].w = 0; _LightMapRectChange[i].h = 0; Drawer.Bind(_LightMapTextures + i); Drawer.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear); long addr = lmAddr + i * BLOCK_WIDTH * BLOCK_HEIGHT * _LightMapBytes; GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)_LightMapBytes, BLOCK_WIDTH, BLOCK_HEIGHT, 0, Drawer.LightMapFormat, PixelType.UnsignedByte, new IntPtr(addr)); } } finally { handle.Free(); } if (_glTexSort.Value == 0) { Drawer.SelectTexture(MTexTarget.TEXTURE0_SGIS); } }
static msurface_t _WarpFace; // used by SubdivideSurface() /// <summary> /// R_InitSky /// called at level load /// A sky texture is 256*128, with the right side being a masked overlay /// </summary> public static void InitSky(texture_t mt) { byte[] src = mt.pixels; int offset = mt.offsets[0]; // make an average value for the back to avoid // a fringe on the top level const int size = 128 * 128; uint[] trans = new uint[size]; uint[] v8to24 = Vid.Table8to24; int r = 0; int g = 0; int b = 0; Union4b rgba = Union4b.Empty; for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { int p = src[offset + i * 256 + j + 128]; rgba.ui0 = v8to24[p]; trans[(i * 128) + j] = rgba.ui0; r += rgba.b0; g += rgba.b1; b += rgba.b2; } } rgba.b0 = (byte)(r / size); rgba.b1 = (byte)(g / size); rgba.b2 = (byte)(b / size); rgba.b3 = 0; uint transpix = rgba.ui0; if (_SolidSkyTexture == 0) { _SolidSkyTexture = Drawer.GenerateTextureNumber(); } Drawer.Bind(_SolidSkyTexture); GL.TexImage2D(TextureTarget.Texture2D, 0, Drawer.SolidFormat, 128, 128, 0, PixelFormat.Rgba, PixelType.UnsignedByte, trans); Drawer.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear); for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { int p = src[offset + i * 256 + j]; if (p == 0) { trans[(i * 128) + j] = transpix; } else { trans[(i * 128) + j] = v8to24[p]; } } } if (_AlphaSkyTexture == 0) { _AlphaSkyTexture = Drawer.GenerateTextureNumber(); } Drawer.Bind(_AlphaSkyTexture); GL.TexImage2D(TextureTarget.Texture2D, 0, Drawer.AlphaFormat, 128, 128, 0, PixelFormat.Rgba, PixelType.UnsignedByte, trans); Drawer.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear); }