⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		});	}	/**	 * R_SetMode	 */	protected boolean R_SetMode() {		boolean fullscreen = (vid_fullscreen.value > 0.0f);		vid_fullscreen.modified = false;		gl_mode.modified = false;		Dimension dim = new Dimension(vid.width, vid.height);		int err; //  enum rserr_t		if ((err = GLimp_SetMode(dim, (int) gl_mode.value, fullscreen)) == rserr_ok) {			gl_state.prev_mode = (int) 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 = GLimp_SetMode(dim, (int) 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");			}			// try setting it back to something safe			if ((err = GLimp_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;	}	float[] r_turbsin = new float[256];	/**	 * R_Init	 */	protected boolean R_Init(int vid_xpos, int vid_ypos) {		assert(Warp.SIN.length == 256) : "warpsin table bug";		// fill r_turbsin		for (int j = 0; j < 256; j++) {			r_turbsin[j] = Warp.SIN[j] * 0.5f;		}		VID.Printf(Defines.PRINT_ALL, "ref_gl version: " + REF_VERSION + '\n');		Draw_GetPalette();		R_Register();		// set our "safe" modes		gl_state.prev_mode = 3;		// create the window and set up the context		if (!R_SetMode()) {			VID.Printf(Defines.PRINT_ALL, "ref_gl::R_Init() - could not R_SetMode()\n");			return false;		}		return true;	}	/**	 * R_Init2	 */	protected boolean R_Init2() {		VID.MenuInit();		/*		** get our various GL strings		*/		gl_config.vendor_string = gl.glGetString(GL11.GL_VENDOR);		VID.Printf(Defines.PRINT_ALL, "GL_VENDOR: " + gl_config.vendor_string + '\n');		gl_config.renderer_string = gl.glGetString(GL11.GL_RENDERER);		VID.Printf(Defines.PRINT_ALL, "GL_RENDERER: " + gl_config.renderer_string + '\n');		gl_config.version_string = gl.glGetString(GL11.GL_VERSION);		VID.Printf(Defines.PRINT_ALL, "GL_VERSION: " + gl_config.version_string + '\n');		gl_config.extensions_string = gl.glGetString(GL11.GL_EXTENSIONS);		VID.Printf(Defines.PRINT_ALL, "GL_EXTENSIONS: " + gl_config.extensions_string + '\n');				gl_config.parseOpenGLVersion();		String renderer_buffer = gl_config.renderer_string.toLowerCase();		String vendor_buffer = gl_config.vendor_string.toLowerCase();		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 = GL_RENDERER_OTHER;		String monolightmap = gl_monolightmap.string.toUpperCase();		if (monolightmap.length() < 2 || monolightmap.charAt(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");			}		}		// power vr can't have anything stay in the framebuffer, so		// the screen needs to redraw the tiled background every frame		if ((gl_config.renderer & GL_RENDERER_POWERVR) != 0) {			Cvar.Set("scr_drawall", "1");		}		else {			Cvar.Set("scr_drawall", "0");		}		// MCD has buffering issues		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 != 0.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");		/*		** grab extensions		*/		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");			//		 qglLockArraysEXT = ( void * ) qwglGetProcAddress( "glLockArraysEXT" );			if (gl_ext_compiled_vertex_array.value != 0.0f)				qglLockArraysEXT = true;			else				qglLockArraysEXT = false;			//		 qglUnlockArraysEXT = ( void * ) qwglGetProcAddress( "glUnlockArraysEXT" );			//qglUnlockArraysEXT = true;		}		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 != 0.0f) {				//			 qglPointParameterfEXT = ( void (APIENTRY *)( GLenum, GLfloat ) ) qwglGetProcAddress( "glPointParameterfEXT" );				qglPointParameterfEXT = true;				//			 qglPointParameterfvEXT = ( void (APIENTRY *)( GLenum, const GLfloat * ) ) qwglGetProcAddress( "glPointParameterfvEXT" );				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");		}		// #ifdef __linux__		//	 if ( strstr( gl_config.extensions_string, "3DFX_set_global_palette" ))		//	 {		//		 if ( gl_ext_palettedtexture->value )		//		 {		//			 VID.Printf( Defines.PRINT_ALL, "...using 3DFX_set_global_palette\n" );		//			 qgl3DfxSetPaletteEXT = ( void ( APIENTRY * ) (GLuint *) )qwglGetProcAddress( "gl3DfxSetPaletteEXT" );		////			 qglColorTableEXT = Fake_glColorTableEXT;		//		 }		//		 else		//		 {		//			 VID.Printf( Defines.PRINT_ALL, "...ignoring 3DFX_set_global_palette\n" );		//		 }		//	 }		//	 else		//	 {		//		 VID.Printf( Defines.PRINT_ALL, "...3DFX_set_global_palette not found\n" );		//	 }		// #endif		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 != 0.0f) {				VID.Printf(Defines.PRINT_ALL, "...using GL_EXT_shared_texture_palette\n");				qglColorTableEXT = false; // true; TODO jogl bug			}			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) {			VID.Printf(Defines.PRINT_ALL, "...using GL_ARB_multitexture\n");			qglActiveTextureARB = true;			GL_TEXTURE0 = ARBMultitexture.GL_TEXTURE0_ARB;			GL_TEXTURE1 = ARBMultitexture.GL_TEXTURE1_ARB;		}		else {			VID.Printf(Defines.PRINT_ALL, "...GL_ARB_multitexture not found\n");		}		if (!(qglActiveTextureARB))			return false;		GL_SetDefaultState();		GL_InitImages();		Mod_Init();		R_InitParticleTexture();		Draw_InitLocal();		int err = gl.glGetError();		if (err != GL11.GL_NO_ERROR)			VID.Printf(				Defines.PRINT_ALL,				"glGetError() = 0x%x\n\t%s\n",				new Vargs(2).add(err).add("" + gl.glGetString(err)));		return true;	}	/**	 * R_Shutdown	 */	protected void R_Shutdown() {		Cmd.RemoveCommand("modellist");		Cmd.RemoveCommand("screenshot");		Cmd.RemoveCommand("imagelist");		Cmd.RemoveCommand("gl_strings");		Mod_FreeAll();		GL_ShutdownImages();		/*		 * shut down OS specific OpenGL stuff like contexts, etc.		 */		GLimp_Shutdown();	}	/**	 * R_BeginFrame	 */	protected void R_BeginFrame(float camera_separation) {		gl_state.camera_separation = camera_separation;		/*		** change modes if necessary		*/		if (gl_mode.modified || vid_fullscreen.modified) {			// FIXME: only restart if CDS is required			cvar_t ref;			ref = Cvar.Get("vid_ref", "lwjgl", 0);			ref.modified = true;		}		if (gl_log.modified) {			GLimp_EnableLogging((gl_log.value != 0.0f));			gl_log.modified = false;		}		if (gl_log.value != 0.0f) {			GLimp_LogNewFrame();		}		/*		** update 3Dfx gamma -- it is expected that a user will do a vid_restart		** after tweaking this value		*/		if (vid_gamma.modified) {			vid_gamma.modified = false;			if ((gl_config.renderer & GL_RENDERER_VOODOO) != 0) {				// wird erstmal nicht gebraucht				/* 				char envbuffer[1024];				float g;								g = 2.00 * ( 0.8 - ( vid_gamma->value - 0.5 ) ) + 1.0F;				Com_sprintf( envbuffer, sizeof(envbuffer), "SSTV2_GAMMA=%f", g );				putenv( envbuffer );				Com_sprintf( envbuffer, sizeof(envbuffer), "SST_GAMMA=%f", g );				putenv( envbuffer );				*/				VID.Printf(Defines.PRINT_DEVELOPER, "gamma anpassung fuer VOODOO nicht gesetzt");			}		}		GLimp_BeginFrame(camera_separation);		/*		** go into 2D mode		*/		gl.glViewport(0, 0, vid.width, vid.height);		gl.glMatrixMode(GL11.GL_PROJECTION);		gl.glLoadIdentity();		gl.glOrtho(0, vid.width, vid.height, 0, -99999, 99999);		gl.glMatrixMode(GL11.GL_MODELVIEW);		gl.glLoadIdentity();		gl.glDisable(GL11.GL_DEPTH_TEST);		gl.glDisable(GL11.GL_CULL_FACE);		gl.glDisable(GL11.GL_BLEND);		gl.glEnable(GL11.GL_ALPHA_TEST);		gl.glColor4f(1, 1, 1, 1);		/*		** draw buffer stuff		*/		if (gl_drawbuffer.modified) {			gl_drawbuffer.modified = false;			if (gl_state.camera_separation == 0 || !gl_state.stereo_enabled) {				if (gl_drawbuffer.string.equalsIgnoreCase("GL_FRONT"))					gl.glDrawBuffer(GL11.GL_FRONT);				else					gl.glDrawBuffer(GL11.GL_BACK);			}		}		/*		** texturemode stuff		*/		if (gl_texturemode.modified) {			GL_TextureMode(gl_texturemode.string);			gl_texturemode.modified = false;		}		if (gl_texturealphamode.modified) {			GL_TextureAlphaMode(gl_texturealphamode.string);			gl_texturealphamode.modified = false;		}		if (gl_texturesolidmode.modified) {			GL_TextureSolidMode(gl_texturesolidmode.string);			gl_texturesolidmode.modified = false;		}		/*		** swapinterval stuff		*/		GL_UpdateSwapInterval();		//		// clear screen if desired		//		R_Clear();	}	int[] r_rawpalette = new int[256];	/**	 * R_SetPalette	 */	protected void R_SetPalette(byte[] palette) {		// 256 RGB values (768 bytes)		// or null		int i;		int color = 0;		if (palette != null) {			int j =0;			for (i = 0; i < 256; i++) {				color = (palette[j++] & 0xFF) << 0;				color |= (palette[j++] & 0xFF) << 8;				color |= (palette[j++] & 0xFF) << 16;				color |= 0xFF000000;				r_rawpalette[i] = color;			}		}		else {			for (i = 0; i < 256; i++) {				r_rawpalette[i] = d_8to24table[i] | 0xff000000;			}		}		GL_SetTexturePalette(r_rawpalette);		gl.glClearColor(0, 0, 0, 0);		gl.glClear(GL11.GL_COLOR_BUFFER_BIT);		gl.glClearColor(1f, 0f, 0.5f, 0.5f);	}	static final int NUM_BEAM_SEGS = 6;	float[][] start_points = new float[NUM_BEAM_SEGS][3];	// array of vec3_t	float[][] end_points = new float[NUM_BEAM_SEGS][3]; // array of vec3_t	// stack variable	private final float[] perpvec = { 0, 0, 0 }; // vec3_t	private final float[] direction = { 0, 0, 0 }; // vec3_t	private final float[] normalized_direction = { 0, 0, 0 }; // vec3_t	private final float[] oldorigin = { 0, 0, 0 }; // vec3_t	private final float[] origin = { 0, 0, 0 }; // vec3_t	/**	 * R_DrawBeam	 */	void R_DrawBeam(entity_t e) {		oldorigin[0] = e.oldorigin[0];		oldorigin[1] = e.oldorigin[1];		oldorigin[2] = e.oldorigin[2];		origin[0] = e.origin[0];		origin[1] = e.origin[1];		origin[2] = e.origin[2];		normalized_direction[0] = direction[0] = oldorigin[0] - origin[0];		normalized_direction[1] = direction[1] = oldorigin[1] - origin[1];		normalized_direction[2] = direction[2] = oldorigin[2] - origin[2];		if (Math3D.VectorNormalize(normalized_direction) == 0.0f)			return;		Math3D.PerpendicularVector(perpvec, normalized_direction);		Math3D.VectorScale(perpvec, e.frame / 2, perpvec);		for (int i = 0; i < 6; i++) {			Math3D.RotatePointAroundVector(				start_points[i],				normalized_direction,				perpvec,				(360.0f / NUM_BEAM_SEGS) * i);			Math3D.VectorAdd(start_points[i], origin, start_points[i]);			Math3D.VectorAdd(start_points[i], direction, end_points[i]);		}		gl.glDisable(GL11.GL_TEXTURE_2D);		gl.glEnable(GL11.GL_BLEND);		gl.glDepthMask(false);		float r = (d_8to24table[e.skinnum & 0xFF]) & 0xFF;		float g = (d_8to24table[e.skinnum & 0xFF] >> 8) & 0xFF;		float b = (d_8to24table[e.skinnum & 0xFF] >> 16) & 0xFF;		r *= 1 / 255.0f;		g *= 1 / 255.0f;		b *= 1 / 255.0f;		gl.glColor4f(r, g, b, e.alpha);		gl.glBegin(GL11.GL_TRIANGLE_STRIP);				float[] v;				for (int i = 0; i < NUM_BEAM_SEGS; i++) {			v = start_points[i];			gl.glVertex3f(v[0], v[1], v[2]);			v = end_points[i];			gl.glVertex3f(v[0], v[1], v[2]);			v = start_points[(i + 1) % NUM_BEAM_SEGS];			gl.glVertex3f(v[0], v[1], v[2]);			v = end_points[(i + 1) % NUM_BEAM_SEGS];			gl.glVertex3f(v[0], v[1], v[2]);		}		gl.glEnd();		gl.glEnable(GL11.GL_TEXTURE_2D);		gl.glDisable(GL11.GL_BLEND);		gl.glDepthMask(true);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -