public override void GL_Strings_f() { VID.Printf(Defines.PRINT_ALL, "GL_VENDOR: " + gl_config.vendor_string + '\\'); VID.Printf(Defines.PRINT_ALL, "GL_RENDERER: " + gl_config.renderer_string + '\\'); VID.Printf(Defines.PRINT_ALL, "GL_VERSION: " + gl_config.version_string + '\\'); VID.Printf(Defines.PRINT_ALL, "GL_EXTENSIONS: " + gl_config.extensions_string + '\\'); }
/* ** GL_Strings_f */ protected void GL_Strings_f() { VID.Printf(Defines.PRINT_ALL, "GL_VENDOR: " + this.gl_config.vendor_string + '\n'); VID.Printf(Defines.PRINT_ALL, "GL_RENDERER: " + this.gl_config.renderer_string + '\n'); VID.Printf(Defines.PRINT_ALL, "GL_VERSION: " + this.gl_config.version_string + '\n'); VID.Printf(Defines.PRINT_ALL, "GL_EXTENSIONS: " + this.gl_config.extensions_string + '\n'); }
public override void Draw_StretchPic(Int32 x, Int32 y, Int32 w, Int32 h, String pic) { image_t image; image = Draw_FindPic(pic); if (image == null) { VID.Printf(Defines.PRINT_ALL, "Can't find pic: " + pic + '\\'); return; } if (scrap_dirty) { Scrap_Upload(); } if (((gl_config.renderer == GL_RENDERER_MCD) || ((gl_config.renderer & GL_RENDERER_RENDITION) != 0)) && !image.has_alpha) { GL.Disable(EnableCap.AlphaTest); } GL_Bind(image.texnum); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(image.sl, image.tl); GL.Vertex2(x, y); GL.TexCoord2(image.sh, image.tl); GL.Vertex2(x + w, y); GL.TexCoord2(image.sh, image.th); GL.Vertex2(x + w, y + h); GL.TexCoord2(image.sl, image.th); GL.Vertex2(x, y + h); GL.End(); if (((gl_config.renderer == GL_RENDERER_MCD) || ((gl_config.renderer & GL_RENDERER_RENDITION) != 0)) && !image.has_alpha) { GL.Enable(EnableCap.AlphaTest); } }
public virtual void Mod_LoadTexinfo(lump_t l) { texinfo_t in_renamed; mtexinfo_t[] out_renamed; mtexinfo_t step; Int32 i, count; Int32 next; String name; if ((l.filelen % texinfo_t.SIZE) != 0) { Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name); } count = l.filelen / texinfo_t.SIZE; out_renamed = new mtexinfo_t[count]; for (i = 0; i < count; i++) { out_renamed[i] = new mtexinfo_t(); } loadmodel.texinfo = out_renamed; loadmodel.numtexinfo = count; ByteBuffer bb = ByteBuffer.Wrap(mod_base, l.fileofs, l.filelen); bb.Order = ByteOrder.LittleEndian; for (i = 0; i < count; i++) { in_renamed = new texinfo_t(bb); out_renamed[i].vecs = in_renamed.vecs; out_renamed[i].flags = in_renamed.flags; next = in_renamed.nexttexinfo; if (next > 0) { out_renamed[i].next = loadmodel.texinfo[next]; } else { out_renamed[i].next = null; } name = "textures/" + in_renamed.texture + ".wal"; out_renamed[i].image = GL_FindImage(name, it_wall); if (out_renamed[i].image == null) { VID.Printf(Defines.PRINT_ALL, "Couldn't load " + name + '\\'); out_renamed[i].image = r_notexture; } } for (i = 0; i < count; i++) { out_renamed[i].numframes = 1; for (step = out_renamed[i].next; (step != null) && (step != out_renamed[i]); step = step.next) { out_renamed[i].numframes++; } } }
public override void Execute() { GL.ClearColor(0f, 0f, 0f, 0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); if (!parent.post_init) { VID.Printf(Defines.PRINT_ALL, "Missing multi-texturing for FastJOGL renderer\\n"); } parent.EndFrame(); }
public override System.Boolean R_Init(Int32 vid_xpos, Int32 vid_ypos) { for (var j = 0; j < 256; j++) { r_turbsin[j] = Warp.SIN[j] * 0.5F; } VID.Printf(Defines.PRINT_ALL, "ref_gl version: " + REF_VERSION + '\\'); Draw_GetPalette(); R_Register(); gl_state.prev_mode = 3; if (!R_SetMode()) { VID.Printf(Defines.PRINT_ALL, "ref_gl::R_Init() - could not R_SetMode()\\n"); return(false); } return(true); }
public virtual void R_RenderView(refdef_t fd) { if (r_norefresh.value != 0F) { return; } r_newrefdef = fd; if (r_newrefdef == null) { Com.Error(Defines.ERR_DROP, "R_RenderView: refdef_t fd is null"); } if (r_worldmodel == null && (r_newrefdef.rdflags & Defines.RDF_NOWORLDMODEL) == 0) { Com.Error(Defines.ERR_DROP, "R_RenderView: NULL worldmodel"); } if (r_speeds.value != 0F) { c_brush_polys = 0; c_alias_polys = 0; } R_PushDlights(); if (gl_finish.value != 0F) { GL.Finish(); } R_SetupFrame(); R_SetFrustum(); R_SetupGL(); R_MarkLeaves(); R_DrawWorld(); R_DrawEntitiesOnList(); R_RenderDlights(); R_DrawParticles(); R_DrawAlphaSurfaces(); R_Flash(); if (r_speeds.value != 0F) { VID.Printf(Defines.PRINT_ALL, "%4i wpoly %4i epoly %i tex %i lmaps\\n", c_brush_polys, c_alias_polys, c_visible_textures, c_visible_lightmaps); } }
protected virtual System.Boolean R_SetMode( ) { var fullscreen = (vid_fullscreen.value > 0F); vid_fullscreen.modified = false; gl_mode.modified = false; Size dim = new Size(vid.GetWidth(), vid.GetHeight()); Int32 err; if ((err = glImpl.SetMode(dim, ( Int32 )gl_mode.value, fullscreen)) == rserr_ok) { gl_state.prev_mode = ( Int32 )gl_mode.value; } else { if (err == rserr_invalid_fullscreen) { Cvar.SetValue("vid_fullscreen", 0); vid_fullscreen.modified = false; VID.Printf(Defines.PRINT_ALL, "ref_gl::R_SetMode() - fullscreen unavailable in this mode\\n"); if ((err = glImpl.SetMode(dim, ( Int32 )gl_mode.value, false)) == rserr_ok) { return(true); } } else if (err == rserr_invalid_mode) { Cvar.SetValue("gl_mode", gl_state.prev_mode); gl_mode.modified = false; VID.Printf(Defines.PRINT_ALL, "ref_gl::R_SetMode() - invalid mode\\n"); } if ((err = glImpl.SetMode(dim, gl_state.prev_mode, false)) != rserr_ok) { VID.Printf(Defines.PRINT_ALL, "ref_gl::R_SetMode() - could not revert to safe mode\\n"); return(false); } } return(true); }
public override void Mod_Modellist_f( ) { Int32 i; model_t mod; Int32 total; total = 0; VID.Printf(Defines.PRINT_ALL, "Loaded models:\\n"); for (i = 0; i < mod_numknown; i++) { mod = mod_known[i]; if (mod.name.Length == 0) { continue; } VID.Printf(Defines.PRINT_ALL, "%8i : %s\\n", mod.extradatasize, mod.name); total += mod.extradatasize; } VID.Printf(Defines.PRINT_ALL, "Total resident: " + total + '\\'); }
public override void GL_ScreenShot_f() { var screnshotIndex = Directory.GetFiles(FS.Gamedir() + "/scrshot/", "jake*.tga") .Select(s => Path.GetFileNameWithoutExtension(s).Replace("jake", "")) .Max(s => int.Parse(s)) + 1; FileStream file = File.OpenWrite(FS.Gamedir() + $"/scrshot/jake{screnshotIndex:00}.tga"); try { using (var bmp = new Bitmap(vid.GetWidth(), vid.GetHeight())) { var data = bmp.LockBits(new Rectangle(0, 0, vid.GetWidth(), vid.GetHeight()), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.ReadPixels(0, 0, vid.GetWidth(), vid.GetHeight(), PixelFormat.Bgr, PixelType.UnsignedByte, data.Scan0); bmp.UnlockBits(data); bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); var encoder = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == System.Drawing.Imaging.ImageFormat.Jpeg.Guid); var encParams = new System.Drawing.Imaging.EncoderParameters() { Param = new[] { new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L) } }; bmp.Save(file, encoder, encParams); } file.Dispose(); } catch (Exception e) { VID.Printf(Defines.PRINT_ALL, e.Message + '\\'); } VID.Printf(Defines.PRINT_ALL, "Wrote " + file.Name + '\\'); }
// =============================================================================== /* * ================ * Mod_Modellist_f * ================ */ protected void Mod_Modellist_f() { int i; model_t mod; int total; total = 0; VID.Printf(Defines.PRINT_ALL, "Loaded models:\n"); for (i = 0; i < this.mod_numknown; i++) { mod = this.mod_known[i]; if (mod.name.Length == 0) { continue; } VID.Printf(Defines.PRINT_ALL, "%8i : %s\n", mod.extradatasize, mod.name); total += mod.extradatasize; } VID.Printf(Defines.PRINT_ALL, "Total resident: " + total + '\n'); }
public virtual System.Boolean R_CullAliasModel(entity_t e) { qfiles.dmdl_t paliashdr = (qfiles.dmdl_t)currentmodel.extradata; if ((e.frame >= paliashdr.num_frames) || (e.frame < 0)) { VID.Printf(Defines.PRINT_ALL, "R_CullAliasModel " + currentmodel.name + ": no such frame " + e.frame + '\\'); e.frame = 0; } if ((e.oldframe >= paliashdr.num_frames) || (e.oldframe < 0)) { VID.Printf(Defines.PRINT_ALL, "R_CullAliasModel " + currentmodel.name + ": no such oldframe " + e.oldframe + '\\'); e.oldframe = 0; } qfiles.daliasframe_t pframe = paliashdr.aliasFrames[e.frame]; qfiles.daliasframe_t poldframe = paliashdr.aliasFrames[e.oldframe]; if (pframe == poldframe) { for (var i = 0; i < 3; i++) { mins[i] = pframe.translate[i]; maxs[i] = mins[i] + pframe.scale[i] * 255; } } else { Single thismaxs, oldmaxs; for (var i = 0; i < 3; i++) { thismaxs = pframe.translate[i] + pframe.scale[i] * 255; oldmaxs = poldframe.translate[i] + poldframe.scale[i] * 255; if (pframe.translate[i] < poldframe.translate[i]) { mins[i] = pframe.translate[i]; } else { mins[i] = poldframe.translate[i]; } if (thismaxs > oldmaxs) { maxs[i] = thismaxs; } else { maxs[i] = oldmaxs; } } } Single[] tmp; for (var i = 0; i < 8; i++) { tmp = bbox[i]; if ((i & 1) != 0) { tmp[0] = mins[0]; } else { tmp[0] = maxs[0]; } if ((i & 2) != 0) { tmp[1] = mins[1]; } else { tmp[1] = maxs[1]; } if ((i & 4) != 0) { tmp[2] = mins[2]; } else { tmp[2] = maxs[2]; } } tmp = mins; Math3D.VectorCopy(e.angles, tmp); tmp[YAW] = -tmp[YAW]; Math3D.AngleVectors(tmp, vectors[0], vectors[1], vectors[2]); for (var i = 0; i < 8; i++) { Math3D.VectorCopy(bbox[i], tmp); bbox[i][0] = Math3D.DotProduct(vectors[0], tmp); bbox[i][1] = -Math3D.DotProduct(vectors[1], tmp); bbox[i][2] = Math3D.DotProduct(vectors[2], tmp); Math3D.VectorAdd(e.origin, bbox[i], bbox[i]); } Int32 f, mask; var aggregatemask = ~0; for (var p = 0; p < 8; p++) { mask = 0; for (f = 0; f < 4; f++) { var dp = Math3D.DotProduct(frustum[f].normal, bbox[p]); if ((dp - frustum[f].dist) < 0) { mask |= (1 << f); } } aggregatemask &= mask; } if (aggregatemask != 0) { return(true); } return(false); }
// /* // ============================================================================== // // SCREEN SHOTS // // ============================================================================== // */ // // typedef struct _TargaHeader { // unsigned char id_length, colormap_type, image_type; // unsigned short colormap_index, colormap_length; // unsigned char colormap_size; // unsigned short x_origin, y_origin, width, height; // unsigned char pixel_size, attributes; // } TargaHeader; /** * GL_ScreenShot_f */ public override void GL_ScreenShot_f() { StringBuilder sb = new(FS.Gamedir() + "/scrshot/screenshot00.tga"); FS.CreatePath(sb.ToString()); var file = sb.ToString(); // find a valid file name var i = 0; var offset = sb.Length - 6; while (File.Exists(file) && i++ < 100) { sb[offset] = (char)(i / 10 + '0'); sb[offset + 1] = (char)(i % 10 + '0'); file = sb.ToString(); } if (i == 100) { VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\n"); return; } try { Stream @out = File.OpenWrite(file); BinaryWriter image = new(@out); // write the TGA header image.Write((byte)0); image.Write((byte)0); image.Write((byte)2); // uncompressed type image.Write(new byte[9]); image.Write((short)Base.vid.getWidth()); // vid.getWidth() image.Write((short)Base.vid.getHeight()); // vid.getHeight() image.Write((byte)24); // pixel size image.Write(new byte[1]); var rgb = new byte[Base.vid.getWidth() * Base.vid.getHeight() * 3]; // change pixel alignment for reading if (Base.vid.getWidth() % 4 != 0) { this.gl.glPixelStorei(OpenGL.GL_PACK_ALIGNMENT, 1); } // OpenGL 1.2+ supports the GL_BGR color format // check the GL_VERSION to use the TARGA BGR order if possible // e.g.: 1.5.2 NVIDIA 66.29 if (this.gl_config.getOpenGLVersion() >= 1.2f) { // read the BGR values into the image buffer this.gl.glReadPixels(0, 0, Base.vid.getWidth(), Base.vid.getHeight(), OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, rgb); } else { // read the RGB values into the image buffer this.gl.glReadPixels(0, 0, Base.vid.getWidth(), Base.vid.getHeight(), OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, rgb); // flip RGB to BGR for (i = 0; i < rgb.Length; i += 3) { image.Write(rgb[i + 2]); image.Write(rgb[i + 1]); image.Write(rgb[i + 0]); } } // reset to default alignment this.gl.glPixelStorei(OpenGL.GL_PACK_ALIGNMENT, 4); // close the file channel @out.Close(); } catch (Exception e) { VID.Printf(Defines.PRINT_ALL, e.Message + '\n'); } VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\n'); }
public unsafe int setMode(Size dim, int mode, bool fullscreen) { var windowSize = new Size(); VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); VID.Printf(Defines.PRINT_ALL, $"...setting mode {mode}:"); if (this.oldDisplayMode == null) { GLFW.Init(); var videoMode = GLFW.GetVideoMode(GLFW.GetPrimaryMonitor())[0]; this.oldDisplayMode = new(videoMode.Width, videoMode.Height, videoMode.RefreshRate, videoMode.RedBits + videoMode.GreenBits + videoMode.BlueBits); } if (!VID.GetModeInfo(ref windowSize, mode)) { VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); return(Base.rserr_invalid_mode); } VID.Printf(Defines.PRINT_ALL, $" {windowSize.Width} {windowSize.Height}{'\n'}"); if (this.window != null) { this.shutdown(); } if (fullscreen) { var displayMode = this.getModeList().FirstOrDefault(displayMode => displayMode.Width == windowSize.Width && displayMode.Height == windowSize.Height) ?? this.oldDisplayMode; this.window = new(GameWindowSettings.Default, new() { Profile = ContextProfile.Compatability, Size = new(displayMode.Width, displayMode.Height), IsFullscreen = true }); VID.Printf( Defines.PRINT_ALL, $"...setting fullscreen {displayMode.Width}x{displayMode.Height}x{displayMode.BitDepth}@{displayMode.RefreshRate}Hz\n" ); } else { this.window = new(GameWindowSettings.Default, new() { Profile = ContextProfile.Compatability, Size = new(windowSize.Width, windowSize.Height) }); VID.Printf(Defines.PRINT_ALL, $"...setting window {windowSize.Width}x{windowSize.Height}\n"); } this.window.Focus(); this.window.Closed += OpenTkDriver.QuitOnClose; OpenTkKBD.Window = this.window; this.window.KeyDown += OpenTkKBD.Listener.KeyDown; this.window.KeyUp += OpenTkKBD.Listener.KeyUp; this.window.MouseDown += OpenTkKBD.Listener.MouseDown; this.window.MouseUp += OpenTkKBD.Listener.MouseUp; this.window.MouseMove += OpenTkKBD.Listener.MouseMove; this.window.MouseWheel += OpenTkKBD.Listener.MouseWheel; Program.UpdateLoop = _ => this.window.Run(); var initialized = false; var updateAccumulator = 0.0; var renderAccumulator = 0.0; this.window.UpdateFrame += args => { updateAccumulator += args.Time * 1000; var elapsed = (int)updateAccumulator; if (elapsed <= 0) { return; } Qcommon.FrameUpdate(elapsed); updateAccumulator -= elapsed; }; this.window.RenderFrame += args => { if (!initialized) { this.init(0, 0); initialized = true; } renderAccumulator += args.Time * 1000; var elapsed = (int)renderAccumulator; if (elapsed <= 0) { return; } Qcommon.FrameRender(elapsed); renderAccumulator -= elapsed; }; this.window.Resize += args => { Base.setVid(this.window.ClientSize.X, this.window.ClientSize.Y); VID.NewWindow(this.window.ClientSize.X, this.window.ClientSize.Y); }; return(Base.rserr_ok); }
public override void R_DrawAliasModel(entity_t e) { Int32 i; qfiles.dmdl_t paliashdr; Single an; Single[][] bbox = new Single[][] { new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 } }; image_t skin; if ((e.flags & Defines.RF_WEAPONMODEL) == 0) { if (R_CullAliasModel(bbox, e)) { return; } } if ((e.flags & Defines.RF_WEAPONMODEL) != 0) { if (r_lefthand.value == 2F) { return; } } paliashdr = (qfiles.dmdl_t)currentmodel.extradata; if ((currententity.flags & (Defines.RF_SHELL_HALF_DAM | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_RED | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE)) != 0) { Math3D.VectorClear(shadelight); if ((currententity.flags & Defines.RF_SHELL_HALF_DAM) != 0) { shadelight[0] = 0.56F; shadelight[1] = 0.59F; shadelight[2] = 0.45F; } if ((currententity.flags & Defines.RF_SHELL_DOUBLE) != 0) { shadelight[0] = 0.9F; shadelight[1] = 0.7F; } if ((currententity.flags & Defines.RF_SHELL_RED) != 0) { shadelight[0] = 1F; } if ((currententity.flags & Defines.RF_SHELL_GREEN) != 0) { shadelight[1] = 1F; } if ((currententity.flags & Defines.RF_SHELL_BLUE) != 0) { shadelight[2] = 1F; } } else if ((currententity.flags & Defines.RF_FULLBRIGHT) != 0) { for (i = 0; i < 3; i++) { shadelight[i] = 1F; } } else { R_LightPoint(currententity.origin, shadelight); if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0) { if (shadelight[0] > shadelight[1]) { if (shadelight[0] > shadelight[2]) { r_lightlevel.value = 150 * shadelight[0]; } else { r_lightlevel.value = 150 * shadelight[2]; } } else { if (shadelight[1] > shadelight[2]) { r_lightlevel.value = 150 * shadelight[1]; } else { r_lightlevel.value = 150 * shadelight[2]; } } } if (gl_monolightmap.string_renamed[0] != '0') { var s = shadelight[0]; if (s < shadelight[1]) { s = shadelight[1]; } if (s < shadelight[2]) { s = shadelight[2]; } shadelight[0] = s; shadelight[1] = s; shadelight[2] = s; } } if ((currententity.flags & Defines.RF_MINLIGHT) != 0) { for (i = 0; i < 3; i++) { if (shadelight[i] > 0.1F) { break; } } if (i == 3) { shadelight[0] = 0.1F; shadelight[1] = 0.1F; shadelight[2] = 0.1F; } } if ((currententity.flags & Defines.RF_GLOW) != 0) { Single scale; Single min; scale = ( Single )(0.1F * Math.Sin(r_newrefdef.time * 7)); for (i = 0; i < 3; i++) { min = shadelight[i] * 0.8F; shadelight[i] += scale; if (shadelight[i] < min) { shadelight[i] = min; } } } if ((r_newrefdef.rdflags & Defines.RDF_IRGOGGLES) != 0 && (currententity.flags & Defines.RF_IR_VISIBLE) != 0) { shadelight[0] = 1F; shadelight[1] = 0F; shadelight[2] = 0F; } shadedots = r_avertexnormal_dots[(( Int32 )(currententity.angles[1] * (SHADEDOT_QUANT / 360))) & (SHADEDOT_QUANT - 1)]; an = ( Single )(currententity.angles[1] / 180 * Math.PI); shadevector[0] = ( Single )Math.Cos(-an); shadevector[1] = ( Single )Math.Sin(-an); shadevector[2] = 1; Math3D.VectorNormalize(shadevector); c_alias_polys += paliashdr.num_tris; if ((currententity.flags & Defines.RF_DEPTHHACK) != 0) { GL.DepthRange(gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin)); } if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0 && (r_lefthand.value == 1F)) { GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); GL.Scale(-1, 1, 1); MYgluPerspective(r_newrefdef.fov_y, ( Single )r_newrefdef.width / r_newrefdef.height, 4, 4096); GL.MatrixMode(MatrixMode.Modelview); GL.CullFace(CullFaceMode.Back); } GL.PushMatrix(); e.angles[PITCH] = -e.angles[PITCH]; R_RotateForEntity(e); e.angles[PITCH] = -e.angles[PITCH]; if (currententity.skin != null) { skin = currententity.skin; } else { if (currententity.skinnum >= qfiles.MAX_MD2SKINS) { skin = currentmodel.skins[0]; } else { skin = currentmodel.skins[currententity.skinnum]; if (skin == null) { skin = currentmodel.skins[0]; } } } if (skin == null) { skin = r_notexture; } GL_Bind(skin.texnum); GL.ShadeModel(ShadingModel.Smooth); GL_TexEnv(( Int32 )All.Modulate); if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) { GL.Enable(EnableCap.Blend); } if ((currententity.frame >= paliashdr.num_frames) || (currententity.frame < 0)) { VID.Printf(Defines.PRINT_ALL, "R_DrawAliasModel " + currentmodel.name + ": no such frame " + currententity.frame + '\\'); currententity.frame = 0; currententity.oldframe = 0; } if ((currententity.oldframe >= paliashdr.num_frames) || (currententity.oldframe < 0)) { VID.Printf(Defines.PRINT_ALL, "R_DrawAliasModel " + currentmodel.name + ": no such oldframe " + currententity.oldframe + '\\'); currententity.frame = 0; currententity.oldframe = 0; } if (r_lerpmodels.value == 0F) { currententity.backlerp = 0; } GL_DrawAliasFrameLerp(paliashdr, currententity.backlerp); GL_TexEnv(( Int32 )All.Replace); GL.ShadeModel(ShadingModel.Flat); GL.PopMatrix(); if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0 && (r_lefthand.value == 1F)) { GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Modelview); GL.CullFace(CullFaceMode.Front); } if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) { GL.Disable(EnableCap.Blend); } if ((currententity.flags & Defines.RF_DEPTHHACK) != 0) { GL.DepthRange(gldepthmin, gldepthmax); } if (gl_shadows.value != 0F && (currententity.flags & (Defines.RF_TRANSLUCENT | Defines.RF_WEAPONMODEL)) == 0) { GL.PushMatrix(); R_RotateForEntity(e); GL.Disable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.Color4(0, 0, 0, 0.5F); GL_DrawAliasShadow(paliashdr, currententity.frame); GL.Enable(EnableCap.Texture2D); GL.Disable(EnableCap.Blend); GL.PopMatrix(); } GL.Color4(1, 1, 1, 1); }
public virtual System.Boolean R_CullAliasModel(Single[][] bbox, entity_t e) { Int32 i; Single[] mins = new Single[] { 0, 0, 0 }; Single[] maxs = new Single[] { 0, 0, 0 }; qfiles.dmdl_t paliashdr; Single[][] vectors = new Single[][] { new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 } }; Single[] thismins = new Single[] { 0, 0, 0 }; Single[] oldmins = new Single[] { 0, 0, 0 }; Single[] thismaxs = new Single[] { 0, 0, 0 }; Single[] oldmaxs = new Single[] { 0, 0, 0 }; qfiles.daliasframe_t pframe, poldframe; Single[] angles = new Single[] { 0, 0, 0 }; paliashdr = (qfiles.dmdl_t)currentmodel.extradata; if ((e.frame >= paliashdr.num_frames) || (e.frame < 0)) { VID.Printf(Defines.PRINT_ALL, "R_CullAliasModel " + currentmodel.name + ": no such frame " + e.frame + '\\'); e.frame = 0; } if ((e.oldframe >= paliashdr.num_frames) || (e.oldframe < 0)) { VID.Printf(Defines.PRINT_ALL, "R_CullAliasModel " + currentmodel.name + ": no such oldframe " + e.oldframe + '\\'); e.oldframe = 0; } pframe = paliashdr.aliasFrames[e.frame]; poldframe = paliashdr.aliasFrames[e.oldframe]; if (pframe == poldframe) { for (i = 0; i < 3; i++) { mins[i] = pframe.translate[i]; maxs[i] = mins[i] + pframe.scale[i] * 255; } } else { for (i = 0; i < 3; i++) { thismins[i] = pframe.translate[i]; thismaxs[i] = thismins[i] + pframe.scale[i] * 255; oldmins[i] = poldframe.translate[i]; oldmaxs[i] = oldmins[i] + poldframe.scale[i] * 255; if (thismins[i] < oldmins[i]) { mins[i] = thismins[i]; } else { mins[i] = oldmins[i]; } if (thismaxs[i] > oldmaxs[i]) { maxs[i] = thismaxs[i]; } else { maxs[i] = oldmaxs[i]; } } } for (i = 0; i < 8; i++) { Single[] tmp = new Single[] { 0, 0, 0 }; if ((i & 1) != 0) { tmp[0] = mins[0]; } else { tmp[0] = maxs[0]; } if ((i & 2) != 0) { tmp[1] = mins[1]; } else { tmp[1] = maxs[1]; } if ((i & 4) != 0) { tmp[2] = mins[2]; } else { tmp[2] = maxs[2]; } Math3D.VectorCopy(tmp, bbox[i]); } Math3D.VectorCopy(e.angles, angles); angles[YAW] = -angles[YAW]; Math3D.AngleVectors(angles, vectors[0], vectors[1], vectors[2]); for (i = 0; i < 8; i++) { Single[] tmp = new Single[] { 0, 0, 0 }; Math3D.VectorCopy(bbox[i], tmp); bbox[i][0] = Math3D.DotProduct(vectors[0], tmp); bbox[i][1] = -Math3D.DotProduct(vectors[1], tmp); bbox[i][2] = Math3D.DotProduct(vectors[2], tmp); Math3D.VectorAdd(e.origin, bbox[i], bbox[i]); } { Int32 p, f; var aggregatemask = ~0; for (p = 0; p < 8; p++) { var mask = 0; for (f = 0; f < 4; f++) { var dp = Math3D.DotProduct(frustum[f].normal, bbox[p]); if ((dp - frustum[f].dist) < 0) { mask |= (1 << f); } } aggregatemask &= mask; } if (aggregatemask != 0) { return(true); } return(false); } }
public override System.Boolean R_Init2( ) { VID.MenuInit(); gl_config.vendor_string = GL.GetString(StringName.Vendor); VID.Printf(Defines.PRINT_ALL, "GL_VENDOR: " + gl_config.vendor_string + '\\'); gl_config.renderer_string = GL.GetString(StringName.Renderer); VID.Printf(Defines.PRINT_ALL, "GL_RENDERER: " + gl_config.renderer_string + '\\'); gl_config.version_string = GL.GetString(StringName.Version); VID.Printf(Defines.PRINT_ALL, "GL_VERSION: " + gl_config.version_string + '\\'); gl_config.extensions_string = GL.GetString(StringName.Extensions); VID.Printf(Defines.PRINT_ALL, "GL_EXTENSIONS: " + gl_config.extensions_string + '\\'); gl_config.ParseOpenGLVersion(); var renderer_buffer = gl_config.renderer_string.ToLower(); var vendor_buffer = gl_config.vendor_string.ToLower(); if (renderer_buffer.IndexOf("voodoo") >= 0) { if (renderer_buffer.IndexOf("rush") < 0) { gl_config.renderer = GL_RENDERER_VOODOO; } else { gl_config.renderer = GL_RENDERER_VOODOO_RUSH; } } else if (vendor_buffer.IndexOf("sgi") >= 0) { gl_config.renderer = GL_RENDERER_SGI; } else if (renderer_buffer.IndexOf("permedia") >= 0) { gl_config.renderer = GL_RENDERER_PERMEDIA2; } else if (renderer_buffer.IndexOf("glint") >= 0) { gl_config.renderer = GL_RENDERER_GLINT_MX; } else if (renderer_buffer.IndexOf("glzicd") >= 0) { gl_config.renderer = GL_RENDERER_REALIZM; } else if (renderer_buffer.IndexOf("gdi") >= 0) { gl_config.renderer = GL_RENDERER_MCD; } else if (renderer_buffer.IndexOf("pcx2") >= 0) { gl_config.renderer = GL_RENDERER_PCX2; } else if (renderer_buffer.IndexOf("verite") >= 0) { gl_config.renderer = GL_RENDERER_RENDITION; } else { gl_config.renderer = unchecked (( Int32 )GL_RENDERER_OTHER); } var monolightmap = gl_monolightmap.string_renamed.ToUpper(); if (monolightmap.Length < 2 || monolightmap[1] != 'F') { if (gl_config.renderer == GL_RENDERER_PERMEDIA2) { Cvar.Set("gl_monolightmap", "A"); VID.Printf(Defines.PRINT_ALL, "...using gl_monolightmap 'a'\\n"); } else if ((gl_config.renderer & GL_RENDERER_POWERVR) != 0) { Cvar.Set("gl_monolightmap", "0"); } else { Cvar.Set("gl_monolightmap", "0"); } } if ((gl_config.renderer & GL_RENDERER_POWERVR) != 0) { Cvar.Set("scr_drawall", "1"); } else { Cvar.Set("scr_drawall", "0"); } if (gl_config.renderer == GL_RENDERER_MCD) { Cvar.SetValue("gl_finish", 1); } if ((gl_config.renderer & GL_RENDERER_3DLABS) != 0) { if (gl_3dlabs_broken.value != 0F) { gl_config.allow_cds = false; } else { gl_config.allow_cds = true; } } else { gl_config.allow_cds = true; } if (gl_config.allow_cds) { VID.Printf(Defines.PRINT_ALL, "...allowing CDS\\n"); } else { VID.Printf(Defines.PRINT_ALL, "...disabling CDS\\n"); } if (gl_config.extensions_string.IndexOf("GL_EXT_compiled_vertex_array") >= 0 || gl_config.extensions_string.IndexOf("GL_SGI_compiled_vertex_array") >= 0) { VID.Printf(Defines.PRINT_ALL, "...enabling GL_EXT_compiled_vertex_array\\n"); if (gl_ext_compiled_vertex_array.value != 0F) { qglLockArraysEXT = true; } else { qglLockArraysEXT = false; } } else { VID.Printf(Defines.PRINT_ALL, "...GL_EXT_compiled_vertex_array not found\\n"); qglLockArraysEXT = false; } if (gl_config.extensions_string.IndexOf("WGL_EXT_swap_control") >= 0) { qwglSwapIntervalEXT = true; VID.Printf(Defines.PRINT_ALL, "...enabling WGL_EXT_swap_control\\n"); } else { qwglSwapIntervalEXT = false; VID.Printf(Defines.PRINT_ALL, "...WGL_EXT_swap_control not found\\n"); } if (gl_config.extensions_string.IndexOf("GL_EXT_point_parameters") >= 0) { if (gl_ext_pointparameters.value != 0F) { qglPointParameterfEXT = true; VID.Printf(Defines.PRINT_ALL, "...using GL_EXT_point_parameters\\n"); } else { VID.Printf(Defines.PRINT_ALL, "...ignoring GL_EXT_point_parameters\\n"); } } else { VID.Printf(Defines.PRINT_ALL, "...GL_EXT_point_parameters not found\\n"); } if (!qglColorTableEXT && gl_config.extensions_string.IndexOf("GL_EXT_paletted_texture") >= 0 && gl_config.extensions_string.IndexOf("GL_EXT_shared_texture_palette") >= 0) { if (gl_ext_palettedtexture.value != 0F) { VID.Printf(Defines.PRINT_ALL, "...using GL_EXT_shared_texture_palette\\n"); qglColorTableEXT = false; } else { VID.Printf(Defines.PRINT_ALL, "...ignoring GL_EXT_shared_texture_palette\\n"); qglColorTableEXT = false; } } else { VID.Printf(Defines.PRINT_ALL, "...GL_EXT_shared_texture_palette not found\\n"); } if (gl_config.extensions_string.IndexOf("GL_ARB_multitexture") >= 0) { try { GL.ClientActiveTexture(TextureUnit.Texture0); VID.Printf(Defines.PRINT_ALL, "...using GL_ARB_multitexture\\n"); qglActiveTextureARB = true; TEXTURE0 = ( Int32 )TextureUnit.Texture0; TEXTURE1 = ( Int32 )TextureUnit.Texture1; } catch (Exception e) { qglActiveTextureARB = false; } } else { qglActiveTextureARB = false; VID.Printf(Defines.PRINT_ALL, "...GL_ARB_multitexture not found\\n"); } if (!(qglActiveTextureARB)) { VID.Printf(Defines.PRINT_ALL, "Missing multi-texturing!\\n"); return(false); } GL_SetDefaultState(); GL_InitImages(); Mod_Init(); R_InitParticleTexture(); Draw_InitLocal(); ErrorCode err = GL.GetError(); if (err != ErrorCode.NoError) { VID.Printf(Defines.PRINT_ALL, "GL.GetError() = 0x%x\\n\\t%s\\n", err, "" + Enum.GetName(typeof(ErrorCode), err)); } glImpl.EndFrame(); return(true); }
public virtual int SetMode(Size dim, int mode, bool fullscreen) { VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\\n"); VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); if (oldDisplayMode == null) { oldDisplayMode = Display.GetDisplayMode(); } if (!VID.GetModeInfo(out var newDim, mode)) { VID.Printf(Defines.PRINT_ALL, " invalid mode\\n"); return(Base.rserr_invalid_mode); } VID.Printf(Defines.PRINT_ALL, " " + newDim.Width + " " + newDim.Height + '\\'); Shutdown(); Display.SetTitle("Jake2 (lwjgl)"); VideoMode VideoMode = FindDisplayMode(newDim); newDim.Width = VideoMode.GetWidth(); newDim.Height = VideoMode.GetHeight(); if (fullscreen) { try { Display.SetDisplayMode(VideoMode); } catch (LWJGLException e) { return(Base.rserr_invalid_mode); } Display.SetLocation(0, 0); try { Display.SetFullscreen(fullscreen); } catch (LWJGLException e) { return(Base.rserr_invalid_fullscreen); } VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + GetModeString(VideoMode) + '\\'); } else { try { Display.SetDisplayMode(VideoMode); } catch (LWJGLException e) { return(Base.rserr_invalid_mode); } try { Display.SetFullscreen(false); } catch (LWJGLException e) { return(Base.rserr_invalid_fullscreen); } } Base.SetVid(newDim.width, newDim.height); try { Display.Create(); } catch (LWJGLException e) { return(Base.rserr_unknown); } VID.NewWindow(newDim.width, newDim.height); return(Base.rserr_ok); }
/* * * R_CullAliasModel */ private bool R_CullAliasModel(float[][] bbox, entity_t e) { int i; float[] mins = { 0, 0, 0 }; float[] maxs = { 0, 0, 0 }; dmdl_t paliashdr; float[][] vectors = { new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 } }; float[] thismins = { 0, 0, 0 }; float[] oldmins = { 0, 0, 0 }; float[] thismaxs = { 0, 0, 0 }; float[] oldmaxs = { 0, 0, 0 }; daliasframe_t pframe, poldframe; float[] angles = { 0, 0, 0 }; paliashdr = (dmdl_t)this.currentmodel.extradata; if (e.frame >= paliashdr.num_frames || e.frame < 0) { VID.Printf(Defines.PRINT_ALL, "R_CullAliasModel " + this.currentmodel.name + ": no such frame " + e.frame + '\n'); e.frame = 0; } if (e.oldframe >= paliashdr.num_frames || e.oldframe < 0) { VID.Printf(Defines.PRINT_ALL, "R_CullAliasModel " + this.currentmodel.name + ": no such oldframe " + e.oldframe + '\n'); e.oldframe = 0; } pframe = paliashdr.aliasFrames[e.frame]; poldframe = paliashdr.aliasFrames[e.oldframe]; /* * * compute axially aligned mins and maxs */ if (pframe == poldframe) { for (i = 0; i < 3; i++) { mins[i] = pframe.translate[i]; maxs[i] = mins[i] + pframe.scale[i] * 255; } } else { for (i = 0; i < 3; i++) { thismins[i] = pframe.translate[i]; thismaxs[i] = thismins[i] + pframe.scale[i] * 255; oldmins[i] = poldframe.translate[i]; oldmaxs[i] = oldmins[i] + poldframe.scale[i] * 255; if (thismins[i] < oldmins[i]) { mins[i] = thismins[i]; } else { mins[i] = oldmins[i]; } if (thismaxs[i] > oldmaxs[i]) { maxs[i] = thismaxs[i]; } else { maxs[i] = oldmaxs[i]; } } } /* * * compute a full bounding box */ for (i = 0; i < 8; i++) { float[] tmp = { 0, 0, 0 }; if ((i & 1) != 0) { tmp[0] = mins[0]; } else { tmp[0] = maxs[0]; } if ((i & 2) != 0) { tmp[1] = mins[1]; } else { tmp[1] = maxs[1]; } if ((i & 4) != 0) { tmp[2] = mins[2]; } else { tmp[2] = maxs[2]; } Math3D.VectorCopy(tmp, bbox[i]); } /* * * rotate the bounding box */ Math3D.VectorCopy(e.angles, angles); angles[Base.YAW] = -angles[Base.YAW]; Math3D.AngleVectors(angles, vectors[0], vectors[1], vectors[2]); for (i = 0; i < 8; i++) { float[] tmp = { 0, 0, 0 }; Math3D.VectorCopy(bbox[i], tmp); bbox[i][0] = Math3D.DotProduct(vectors[0], tmp); bbox[i][1] = -Math3D.DotProduct(vectors[1], tmp); bbox[i][2] = Math3D.DotProduct(vectors[2], tmp); Math3D.VectorAdd(e.origin, bbox[i], bbox[i]); } { int p, f; var aggregatemask = ~0; // 0xFFFFFFFF for (p = 0; p < 8; p++) { var mask = 0; for (f = 0; f < 4; f++) { var dp = Math3D.DotProduct(this.frustum[f].normal, bbox[p]); if (dp - this.frustum[f].dist < 0) { mask |= 1 << f; } } aggregatemask &= mask; } if (aggregatemask != 0) { return(true); } return(false); } }
public override void R_BeginFrame(Single camera_separation) { vid.Update(); gl_state.camera_separation = camera_separation; if (gl_mode.modified || vid_fullscreen.modified) { cvar_t ref_renamed; ref_renamed = Cvar.Get("vid_ref", "lwjgl", 0); ref_renamed.modified = true; } if (gl_log.modified) { glImpl.EnableLogging((gl_log.value != 0F)); gl_log.modified = false; } if (gl_log.value != 0F) { glImpl.LogNewFrame(); } if (vid_gamma.modified) { vid_gamma.modified = false; if ((gl_config.renderer & GL_RENDERER_VOODOO) != 0) { VID.Printf(Defines.PRINT_DEVELOPER, "gamma anpassung fuer VOODOO nicht gesetzt"); } } glImpl.BeginFrame(camera_separation); GL.Viewport(0, 0, vid.GetWidth(), vid.GetHeight()); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, vid.GetWidth(), vid.GetHeight(), 0, -99999, 99999); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.Blend); GL.Enable(EnableCap.AlphaTest); GL.Color4(1, 1, 1, 1); if (gl_drawbuffer.modified) { gl_drawbuffer.modified = false; if (gl_state.camera_separation == 0 || !gl_state.stereo_enabled) { if (gl_drawbuffer.string_renamed.EqualsIgnoreCase("GL_FRONT")) { GL.DrawBuffer(DrawBufferMode.Front); } else { GL.DrawBuffer(DrawBufferMode.Back); } } } if (gl_texturemode.modified) { GL_TextureMode(gl_texturemode.string_renamed); gl_texturemode.modified = false; } if (gl_texturealphamode.modified) { GL_TextureAlphaMode(gl_texturealphamode.string_renamed); gl_texturealphamode.modified = false; } if (gl_texturesolidmode.modified) { GL_TextureSolidMode(gl_texturesolidmode.string_renamed); gl_texturesolidmode.modified = false; } GL_UpdateSwapInterval(); R_Clear(); }
/* * ================= R_DrawAliasModel * * ================= */ protected void R_DrawAliasModel(entity_t e) { int i; dmdl_t paliashdr; float an; // bounding box float[][] bbox = { new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 } }; image_t skin; if ((e.flags & Defines.RF_WEAPONMODEL) == 0) { if (this.R_CullAliasModel(bbox, e)) { return; } } if ((e.flags & Defines.RF_WEAPONMODEL) != 0) { if (this.r_lefthand.value == 2.0f) { return; } } paliashdr = (dmdl_t)this.currentmodel.extradata; // // get lighting information // // PMM - rewrote, reordered to handle new shells & mixing // PMM - 3.20 code .. replaced with original way of doing it to keep mod // authors happy // if ((this.currententity.flags & (Defines.RF_SHELL_HALF_DAM | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_RED | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE)) != 0) { Math3D.VectorClear(this.shadelight); if ((this.currententity.flags & Defines.RF_SHELL_HALF_DAM) != 0) { this.shadelight[0] = 0.56f; this.shadelight[1] = 0.59f; this.shadelight[2] = 0.45f; } if ((this.currententity.flags & Defines.RF_SHELL_DOUBLE) != 0) { this.shadelight[0] = 0.9f; this.shadelight[1] = 0.7f; } if ((this.currententity.flags & Defines.RF_SHELL_RED) != 0) { this.shadelight[0] = 1.0f; } if ((this.currententity.flags & Defines.RF_SHELL_GREEN) != 0) { this.shadelight[1] = 1.0f; } if ((this.currententity.flags & Defines.RF_SHELL_BLUE) != 0) { this.shadelight[2] = 1.0f; } } else if ((this.currententity.flags & Defines.RF_FULLBRIGHT) != 0) { for (i = 0; i < 3; i++) { this.shadelight[i] = 1.0f; } } else { this.R_LightPoint(this.currententity.origin, this.shadelight); // player lighting hack for communication back to server // big hack! if ((this.currententity.flags & Defines.RF_WEAPONMODEL) != 0) { // pick the greatest component, which should be the same // as the mono value returned by software if (this.shadelight[0] > this.shadelight[1]) { if (this.shadelight[0] > this.shadelight[2]) { this.r_lightlevel.value = 150 * this.shadelight[0]; } else { this.r_lightlevel.value = 150 * this.shadelight[2]; } } else { if (this.shadelight[1] > this.shadelight[2]) { this.r_lightlevel.value = 150 * this.shadelight[1]; } else { this.r_lightlevel.value = 150 * this.shadelight[2]; } } } if (this.gl_monolightmap.@string[0] != '0') { var s = this.shadelight[0]; if (s < this.shadelight[1]) { s = this.shadelight[1]; } if (s < this.shadelight[2]) { s = this.shadelight[2]; } this.shadelight[0] = s; this.shadelight[1] = s; this.shadelight[2] = s; } } if ((this.currententity.flags & Defines.RF_MINLIGHT) != 0) { for (i = 0; i < 3; i++) { if (this.shadelight[i] > 0.1f) { break; } } if (i == 3) { this.shadelight[0] = 0.1f; this.shadelight[1] = 0.1f; this.shadelight[2] = 0.1f; } } if ((this.currententity.flags & Defines.RF_GLOW) != 0) { // bonus items will // pulse with time float scale; float min; scale = (float)(0.1f * Math.Sin(this.r_newrefdef.time * 7)); for (i = 0; i < 3; i++) { min = this.shadelight[i] * 0.8f; this.shadelight[i] += scale; if (this.shadelight[i] < min) { this.shadelight[i] = min; } } } // ================= // PGM ir goggles color override if ((this.r_newrefdef.rdflags & Defines.RDF_IRGOGGLES) != 0 && (this.currententity.flags & Defines.RF_IR_VISIBLE) != 0) { this.shadelight[0] = 1.0f; this.shadelight[1] = 0.0f; this.shadelight[2] = 0.0f; } // PGM // ================= this.shadedots = this.r_avertexnormal_dots[(int)(this.currententity.angles[1] * (OpenGLRenderApi.SHADEDOT_QUANT / 360.0)) & (OpenGLRenderApi.SHADEDOT_QUANT - 1)]; an = (float)(this.currententity.angles[1] / 180 * Math.PI); this.shadevector[0] = (float)Math.Cos(-an); this.shadevector[1] = (float)Math.Sin(-an); this.shadevector[2] = 1; Math3D.VectorNormalize(this.shadevector); // // locate the proper data // this.c_alias_polys += paliashdr.num_tris; // // draw all the triangles // if ((this.currententity.flags & Defines.RF_DEPTHHACK) != 0) { // hack the depth range to prevent view model from poking into walls this.gl.glDepthRange(this.gldepthmin, this.gldepthmin + 0.3 * (this.gldepthmax - this.gldepthmin)); } if ((this.currententity.flags & Defines.RF_WEAPONMODEL) != 0 && this.r_lefthand.value == 1.0f) { this.gl.glMatrixMode(OpenGL.GL_PROJECTION); this.gl.glPushMatrix(); this.gl.glLoadIdentity(); this.gl.glScalef(-1, 1, 1); this.MYgluPerspective(this.r_newrefdef.fov_y, (float)this.r_newrefdef.width / this.r_newrefdef.height, 4, 4096); this.gl.glMatrixMode(OpenGL.GL_MODELVIEW); this.gl.glCullFace(OpenGL.GL_BACK); } this.gl.glPushMatrix(); e.angles[Base.PITCH] = -e.angles[Base.PITCH]; // sigh. this.R_RotateForEntity(e); e.angles[Base.PITCH] = -e.angles[Base.PITCH]; // sigh. // select skin if (this.currententity.skin != null) { skin = this.currententity.skin; // custom player skin } else { if (this.currententity.skinnum >= qfiles.MAX_MD2SKINS) { skin = this.currentmodel.skins[0]; } else { skin = this.currentmodel.skins[this.currententity.skinnum]; if (skin == null) { skin = this.currentmodel.skins[0]; } } } if (skin == null) { skin = this.r_notexture; // fallback... } this.GL_Bind(skin.texnum); // draw it this.gl.glShadeModel(OpenGL.GL_SMOOTH); this.GL_TexEnv(OpenGL.GL_MODULATE); if ((this.currententity.flags & Defines.RF_TRANSLUCENT) != 0) { this.gl.glEnable(OpenGL.GL_BLEND); } if (this.currententity.frame >= paliashdr.num_frames || this.currententity.frame < 0) { VID.Printf(Defines.PRINT_ALL, "R_DrawAliasModel " + this.currentmodel.name + ": no such frame " + this.currententity.frame + '\n'); this.currententity.frame = 0; this.currententity.oldframe = 0; } if (this.currententity.oldframe >= paliashdr.num_frames || this.currententity.oldframe < 0) { VID.Printf(Defines.PRINT_ALL, "R_DrawAliasModel " + this.currentmodel.name + ": no such oldframe " + this.currententity.oldframe + '\n'); this.currententity.frame = 0; this.currententity.oldframe = 0; } if (this.r_lerpmodels.value == 0.0f) { this.currententity.backlerp = 0; } this.GL_DrawAliasFrameLerp(paliashdr, this.currententity.backlerp); this.GL_TexEnv(OpenGL.GL_REPLACE); this.gl.glShadeModel(OpenGL.GL_FLAT); this.gl.glPopMatrix(); if ((this.currententity.flags & Defines.RF_WEAPONMODEL) != 0 && this.r_lefthand.value == 1.0F) { this.gl.glMatrixMode(OpenGL.GL_PROJECTION); this.gl.glPopMatrix(); this.gl.glMatrixMode(OpenGL.GL_MODELVIEW); this.gl.glCullFace(OpenGL.GL_FRONT); } if ((this.currententity.flags & Defines.RF_TRANSLUCENT) != 0) { this.gl.glDisable(OpenGL.GL_BLEND); } if ((this.currententity.flags & Defines.RF_DEPTHHACK) != 0) { this.gl.glDepthRange(this.gldepthmin, this.gldepthmax); } if (this.gl_shadows.value != 0.0f && (this.currententity.flags & (Defines.RF_TRANSLUCENT | Defines.RF_WEAPONMODEL)) == 0) { this.gl.glPushMatrix(); this.R_RotateForEntity(e); this.gl.glDisable(OpenGL.GL_TEXTURE_2D); this.gl.glEnable(OpenGL.GL_BLEND); this.gl.glColor4f(0, 0, 0, 0.5f); this.GL_DrawAliasShadow(paliashdr, this.currententity.frame); this.gl.glEnable(OpenGL.GL_TEXTURE_2D); this.gl.glDisable(OpenGL.GL_BLEND); this.gl.glPopMatrix(); } this.gl.glColor4f(1, 1, 1, 1); }
public virtual int SetMode(Size dim, int mode, bool fullscreen) { VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\\n"); VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); //if (Globals.appletMode && container == null) //{ // container = (Container)Globals.applet; //} if (device == null) { GraphicsEnvironment env = GraphicsEnvironment.GetLocalGraphicsEnvironment(); device = env.GetDefaultScreenDevice(); } if (oldDisplayMode == null) { oldDisplayMode = device.GetDisplayMode(); } if (!VID.GetModeInfo(out var newDim, mode)) { VID.Printf(Defines.PRINT_ALL, " invalid mode\\n"); return(Base.rserr_invalid_mode); } VID.Printf(Defines.PRINT_ALL, " " + newDim.Width + " " + newDim.Height + '\\'); if (!Globals.appletMode) { if (window != null) { Shutdown(); } window = new Frame("Jake2 (jsr231)"); container = window; ImageIcon icon = new ImageIcon(GetType().GetResource("/icon-small.png")); window.SetIconImage(icon.GetImage()); window.SetLayout(new GridBagLayout()); window.AddWindowListener(new AnonymousWindowAdapter(this)); } if (Globals.appletMode) { Shutdown(); fullscreen = false; JOGLKBD.Init(container); } Display canvas = new Display(new GLCapabilities()); canvas.SetFocusTraversalKeysEnabled(false); canvas.SetSize(newDim.Width, newDim.Height); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.weightx = gbc.weighty = 1; container.AddComponentListener(JOGLKBD.listener); canvas.AddKeyListener(JOGLKBD.listener); canvas.AddMouseListener(JOGLKBD.listener); canvas.AddMouseMotionListener(JOGLKBD.listener); canvas.AddMouseWheelListener(JOGLKBD.listener); if (fullscreen) { container.Add(canvas, gbc); VideoMode VideoMode = FindDisplayMode(newDim); newDim.Width = VideoMode.GetWidth(); newDim.Height = VideoMode.GetHeight(); window.SetUndecorated(true); window.SetResizable(false); device.SetFullScreenWindow(window); if (device.IsFullScreenSupported()) { device.SetDisplayMode(VideoMode); } window.SetLocation(0, 0); window.SetSize(VideoMode.GetWidth(), VideoMode.GetHeight()); canvas.SetSize(VideoMode.GetWidth(), VideoMode.GetHeight()); VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + GetModeString(VideoMode) + '\\'); } else { if (!Globals.appletMode) { container.Add(canvas, gbc); Frame f2 = window; try { EventQueue.InvokeAndWait(new AnonymousRunnable(this)); } catch (Exception e) { e.PrintStackTrace(); } } else { Display fd = canvas; try { EventQueue.InvokeAndWait(new AnonymousRunnable1(this)); } catch (Exception e) { e.PrintStackTrace(); } } } if (!Globals.appletMode) { while (!canvas.IsDisplayable() || !window.IsDisplayable()) { try { Thread.Sleep(100); } catch (InterruptedException e) { } } } canvas.RequestFocus(); this.display = canvas; SetGL(display.GetGL()); Init(0, 0); return(Base.rserr_ok); }
public virtual int SetMode(Size dim, int mode, bool fullscreen) { VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\\n"); VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); unsafe { Monitor *device = GLFW.GetPrimaryMonitor(); if (oldDisplayMode == null) { oldDisplayMode = GLFW.GetVideoMode(device)[0]; } } if (!VID.GetModeInfo(out var newDim, mode)) { VID.Printf(Defines.PRINT_ALL, " invalid mode\\n"); return(Base.rserr_invalid_mode); } VID.Printf(Defines.PRINT_ALL, " " + newDim.Width + " " + newDim.Height + '\\'); Shutdown(); var newInstance = (window == null); if (!newInstance) { window.Dispose(); } window = new GameWindow(new GameWindowSettings(), new NativeWindowSettings { Title = "Q2Sharp (jogl)", Size = new OpenTK.Mathematics.Vector2i(newDim.Width, newDim.Height), StartVisible = false, WindowBorder = OpenTK.Windowing.Common.WindowBorder.Fixed, IsFullscreen = false //Icon = new OpenTK.Windowing.Common.Input.WindowIcon(new OpenTK.Windowing.Common.Input.Image(32,32,null)), }); window.RenderFrame += (t) => Program.Frame(); Program.RunWindow += () => window.Run(); //ImageIcon icon = new ImageIcon(GetType().GetResource("/icon-small.png")); Bitmap bitmap = (Bitmap)Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream("/icon-small.png")); byte[] pixels = new byte[bitmap.Width * bitmap.Height]; for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { var color = bitmap.GetPixel(x, y); Array.Copy(new byte[] { color.R, color.G, color.B, color.A }, 0, pixels, (y * bitmap.Width + x) * 4, 4); } } Image icon = new Image(bitmap.Width, bitmap.Height, pixels); window.Icon = new WindowIcon(icon); window.Minimized += (e) => JOGLKBD.listener.ComponentHidden(e); window.Maximized += (e) => { JOGLKBD.c = window; JOGLKBD.listener.ComponentShown(e); }; window.Move += (e) => JOGLKBD.listener.ComponentMoved(e); window.Closing += (e) => Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); window.Resize += (e) => JOGLKBD.listener.ComponentResized(e); window.KeyDown += (e) => JOGLKBD.listener.KeyPressed(e); window.KeyUp += (e) => JOGLKBD.listener.KeyReleased(e); window.TextInput += (e) => JOGLKBD.listener.KeyTyped(e); window.MouseEnter += () => JOGLKBD.listener.MouseEntered(); window.MouseLeave += () => JOGLKBD.listener.MouseExited(); window.MouseMove += (e) => JOGLKBD.listener.MouseMoved(e); window.MouseDown += (e) => JOGLKBD.listener.MousePressed(e); window.MouseUp += (e) => JOGLKBD.listener.MouseReleased(e); window.MouseWheel += (e) => JOGLKBD.listener.MouseWheelMoved(e); //window.drag += ( e ) => JOGLKBD.listener.MouseDragged( e ); if (fullscreen) { window.WindowState = OpenTK.Windowing.Common.WindowState.Fullscreen; VideoMode VideoMode = FindDisplayMode(newDim); newDim.Width = VideoMode.Width; newDim.Height = VideoMode.Height; window.WindowState = WindowState.Fullscreen; if (window.IsFullscreen) { unsafe { GLFW.SetWindowSize(window.WindowPtr, VideoMode.Width, VideoMode.Height); } } window.Location = new OpenTK.Mathematics.Vector2i(); window.Size = new OpenTK.Mathematics.Vector2i(VideoMode.Width, VideoMode.Height); VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + GetModeString(VideoMode) + '\\'); window.IsVisible = true; } else { window.Location = new OpenTK.Mathematics.Vector2i(window_xpos, window_ypos); window.IsVisible = true; } Base.SetVid(newDim.Width, newDim.Height); VID.NewWindow(newDim.Width, newDim.Height); return(Base.rserr_ok); }
public override void GL_ScreenShot_f() { StringBuffer sb = new StringBuffer(FS.Gamedir() + "/scrshot/jake00.tga"); FS.CreatePath(sb.ToString()); FileInfo file = new FileInfo(sb.ToString()); int i = 0; int offset = sb.Length - 6; while (file.Exists && i++ < 100) { sb[offset] = (char)((i / 10) + '0'); sb[offset + 1] = (char)((i % 10) + '0'); file = new FileInfo(sb.ToString()); } if (i == 100) { VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\\n"); return; } try { FileStream out_renamed = File.OpenWrite(file.FullName); int fileLength = TGA_HEADER_SIZE + vid.GetWidth() * vid.GetHeight() * 3; out_renamed.SetLength(fileLength); ByteBuffer image = ByteBuffer.Allocate((int)file.Length); image.Put(0, (byte)0).Put(1, (byte)0); image.Put(2, (byte)2); image.Put(12, (byte)(vid.GetWidth() & 0xFF)); image.Put(13, (byte)(vid.GetWidth() >> 8)); image.Put(14, (byte)(vid.GetHeight() & 0xFF)); image.Put(15, (byte)(vid.GetHeight() >> 8)); image.Put(16, (byte)24); image.Position = TGA_HEADER_SIZE; ByteBuffer rgb = image.Slice(); if (vid.GetWidth() % 4 != 0) { GL.PixelStore(PixelStoreParameter.PackAlignment, 1); } if (gl_config.GetOpenGLVersion() >= 1.2F) { Byte[] pixels = new Byte[vid.GetWidth() * vid.GetHeight() * 3]; GL.ReadPixels(0, 0, vid.GetWidth(), vid.GetHeight(), PixelFormat.Bgr, PixelType.UnsignedByte, pixels); rgb = ByteBuffer.Allocate(pixels.Length); rgb.Put(pixels); } else { Byte[] pixels = new Byte[vid.GetWidth() * vid.GetHeight() * 3]; GL.ReadPixels(0, 0, vid.GetWidth(), vid.GetHeight(), PixelFormat.Rgb, PixelType.UnsignedByte, pixels); rgb = ByteBuffer.Allocate(pixels.Length); rgb.Put(pixels); byte tmp; for (i = TGA_HEADER_SIZE; i < fileLength; i += 3) { tmp = image.Get(i); image.Put(i, image.Get(i + 2)); image.Put(i + 2, tmp); } } GL.PixelStore(PixelStoreParameter.PackAlignment, 4); out_renamed.Write(image.Array, 0, image.Array.Length); out_renamed.Dispose(); } catch (IOException e) { VID.Printf(Defines.PRINT_ALL, e.ToString() + '\\'); } VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\\'); }