예제 #1
0
파일: video.c 프로젝트: stuaxo/dosemu2
void
video_config_init(void) {
  screen_mask = 1 << (((int)phys_text_base-0xA0000)/4096);

  video_init();

  reserve_video_memory();
}
예제 #2
0
파일: video.c 프로젝트: aunali1/exopc
void video_config_init(void)
{
/*     gettermcap(0); */

    switch (config.cardtype) {
    case CARD_MDA:
	{
	    configuration |= (MDA_CONF_SCREEN_MODE);
	    video_mode = MDA_INIT_SCREEN_MODE;
	    phys_text_base = MDA_PHYS_TEXT_BASE;
	    virt_text_base = MDA_VIRT_TEXT_BASE;
	    video_combo = MDA_VIDEO_COMBO;
	    video_subsys = MDA_VIDEO_SUBSYS;
	    break;
	}
    case CARD_CGA:
	{
	    configuration |= (CGA_CONF_SCREEN_MODE);
	    video_mode = CGA_INIT_SCREEN_MODE;
	    phys_text_base = CGA_PHYS_TEXT_BASE;
	    virt_text_base = CGA_VIRT_TEXT_BASE;
	    video_combo = CGA_VIDEO_COMBO;
	    video_subsys = CGA_VIDEO_SUBSYS;

	    break;
	}
    case CARD_EGA:
	{
	    configuration |= (EGA_CONF_SCREEN_MODE);
	    video_mode = EGA_INIT_SCREEN_MODE;
	    phys_text_base = EGA_PHYS_TEXT_BASE;
	    virt_text_base = EGA_VIRT_TEXT_BASE;
	    video_combo = EGA_VIDEO_COMBO;
	    video_subsys = EGA_VIDEO_SUBSYS;
	    break;
	}
    case CARD_VGA:
	{
	    configuration |= (VGA_CONF_SCREEN_MODE);
	    video_mode = VGA_INIT_SCREEN_MODE;
	    phys_text_base = VGA_PHYS_TEXT_BASE;
	    virt_text_base = VGA_VIRT_TEXT_BASE;
	    video_combo = VGA_VIDEO_COMBO;
	    video_subsys = VGA_VIDEO_SUBSYS;
	    break;
	}
    default:			/* or Terminal, is this correct ? */
	{
	    configuration |= (CGA_CONF_SCREEN_MODE);
	    video_mode = CGA_INIT_SCREEN_MODE;
	    phys_text_base = CGA_PHYS_TEXT_BASE;
	    virt_text_base = CGA_VIRT_TEXT_BASE;
	    video_combo = CGA_VIDEO_COMBO;
	    video_subsys = CGA_VIDEO_SUBSYS;
	    break;
	}
    }

#if 0                 /* FIXME XXX  why/where does config.console get cleared?  */
    if (!config.console) {
	/* NOTE: BIG FAT WARNING !!!
	 *       without this you will reproduceable KILL LINUX
	 *       (seen with Linux-2.0.28)            ^^^^^^^^^^
	 *       This happens in xterm, not console and not xdos.
	 *       I was unable to trace it down, because directly at
	 *       startup you get a black screen and no logs are left
	 *       once you repaired your files system :(
	 *       Though this is a userspace bug, it should not
	 *       kill the kernel IMHO. -- Hans
	 */
	v_printf("VID: not running on console - resetting to terminal mode\n");
	config.console_video = 0;
/*      scr_state.console_no = 0; */
	config.console_keyb = 0;
	config.console_video = 0;
	config.mapped_bios = 0;
	config.vga = 0;
	config.graphics = 0;
	config.console = 0;
	if (config.speaker == SPKR_NATIVE)
	    config.speaker = SPKR_EMULATED;
    }
#endif
    video_page = 0;
    screen_mask = 1 << (((int) phys_text_base - 0xA0000) / 4096);
    screen_adr = SCREEN_ADR(0);
    if (!config.vga) {
	WRITE_BYTE(BIOS_CURRENT_SCREEN_PAGE, 0x0);	/* Current Screen Page */
	WRITE_WORD(BIOS_CURSOR_SHAPE, (configuration & MDA_CONF_SCREEN_MODE) ? 0x0A0B : 0x0607);

	/* This is needed in the video stuff. Grabbed from boot(). */
	if ((configuration & MDA_CONF_SCREEN_MODE) == MDA_CONF_SCREEN_MODE)
	    WRITE_WORD(BIOS_VIDEO_PORT, 0x3b4);		/* base port of CRTC - IMPORTANT! */
	else
	    WRITE_WORD(BIOS_VIDEO_PORT, 0x3d4);		/* base port of CRTC - IMPORTANT! */

	WRITE_BYTE(BIOS_VDU_CONTROL, 9);	/* current 3x8 (x=b or d) value */

	WRITE_BYTE(BIOS_VIDEO_MODE, video_mode);	/* video mode */
	set_video_bios_size();
	WRITE_WORD(BIOS_VIDEO_MEMORY_ADDRESS, 0);	/* offset of current page in buffer */

	WRITE_WORD(BIOS_FONT_HEIGHT, 16);

	/* XXX - these are the values for VGA color!
	   should reflect the real display hardware. */
	WRITE_BYTE(BIOS_VIDEO_INFO_0, 0x60);
	WRITE_BYTE(BIOS_VIDEO_INFO_1, 0xF9);
	WRITE_BYTE(BIOS_VIDEO_INFO_2, 0x51);
	WRITE_BYTE(BIOS_VIDEO_COMBO, video_combo);

	WRITE_DWORD(BIOS_VIDEO_SAVEPTR, 0);	/* pointer to video table */
    }

/*     if (config.console_video && !config.usesX) */
/* 	set_process_control(); */
    if (config.console_video) {
	set_console_video();
    }
/*     if (config.usesX) */
/* 	set_consoleX_video(); */

    video_init();

    reserve_video_memory();
    get_video_ram(0);
}
예제 #3
0
int main () {
	restart_gl_log ();
	start_gl ();
	
	reserve_video_memory ();

	// tell GL to only draw onto a pixel if the shape is closer to the viewer
	glEnable (GL_DEPTH_TEST); // enable depth-testing
	glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"

	GLfloat points[] = {
		-0.5f, -0.5f,  0.0f,
		 0.5f, -0.5f,  0.0f,
		 0.5f,  0.5f,  0.0f,
		 0.5f,  0.5f,  0.0f,
		-0.5f,  0.5f,  0.0f,
		-0.5f, -0.5f,  0.0f
	};
	
	GLfloat texcoords[] = {
		0.0f, 0.0f,
		1.0f, 0.0f,
		1.0f, 1.0f,
		1.0f, 1.0f,
		0.0f, 1.0f,
		0.0f, 0.0f
	};
	
	GLuint points_vbo;
	glGenBuffers (1, &points_vbo);
	glBindBuffer (GL_ARRAY_BUFFER, points_vbo);
	glBufferData (GL_ARRAY_BUFFER, 18 * sizeof (GLfloat), points, GL_STATIC_DRAW);
	
	GLuint texcoords_vbo;
	glGenBuffers (1, &texcoords_vbo);
	glBindBuffer (GL_ARRAY_BUFFER, texcoords_vbo);
	glBufferData (GL_ARRAY_BUFFER, 12 * sizeof (GLfloat), texcoords, GL_STATIC_DRAW);
	
	GLuint vao;
	glGenVertexArrays (1, &vao);
	glBindVertexArray (vao);
	glBindBuffer (GL_ARRAY_BUFFER, points_vbo);
	glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
	glBindBuffer (GL_ARRAY_BUFFER, texcoords_vbo);
	glVertexAttribPointer (1, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray (0);
	glEnableVertexAttribArray (1);
	
	GLuint shader_programme = create_programme_from_files (
		"test_vs.glsl", "test_fs.glsl");
	
	#define ONE_DEG_IN_RAD (2.0 * M_PI) / 360.0 // 0.017444444
	// input variables
	float near = 0.1f; // clipping plane
	float far = 100.0f; // clipping plane
	float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
	float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
	// matrix components
	float range = tan (fov * 0.5f) * near;
	float Sx = (2.0f * near) / (range * aspect + range * aspect);
	float Sy = near / range;
	float Sz = -(far + near) / (far - near);
	float Pz = -(2.0f * far * near) / (far - near);
	GLfloat proj_mat[] = {
		Sx, 0.0f, 0.0f, 0.0f,
		0.0f, Sy, 0.0f, 0.0f,
		0.0f, 0.0f, Sz, -1.0f,
		0.0f, 0.0f, Pz, 0.0f
	};
	
		
	float cam_speed = 1.0f; // 1 unit per second
	float cam_yaw_speed = 10.0f; // 10 degrees per second
	float cam_pos[] = {0.0f, 0.0f, 2.0f}; // don't start at zero, or we will be too close
	float cam_yaw = 0.0f; // y-rotation in degrees
	mat4 T = translate (identity_mat4 (), vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2]));
	mat4 R = rotate_y_deg (identity_mat4 (), -cam_yaw);
	mat4 view_mat = R * T;
	
	int view_mat_location = glGetUniformLocation (shader_programme, "view");
	glUseProgram (shader_programme);
	glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view_mat.m);
	int proj_mat_location = glGetUniformLocation (shader_programme, "proj");
	glUseProgram (shader_programme);
	glUniformMatrix4fv (proj_mat_location, 1, GL_FALSE, proj_mat);
	
	// load texture
	GLuint tex;
	assert (load_texture ("skulluvmap.png", &tex));
	
	
	glEnable (GL_CULL_FACE); // cull face
	glCullFace (GL_BACK); // cull back face
	glFrontFace (GL_CCW); // GL_CCW for counter clock-wise
	
	// initialise timers
	bool dump_video = false;
	double video_timer = 0.0; // time video has been recording
	double video_dump_timer = 0.0; // timer for next frame grab
	double frame_time = 0.04; // 1/25 seconds of time
	
	while (!glfwWindowShouldClose (g_window)) {
		static double previous_seconds = glfwGetTime ();
		double current_seconds = glfwGetTime ();
		double elapsed_seconds = current_seconds - previous_seconds;
		previous_seconds = current_seconds;
		
		if (dump_video) {
			// elapsed_seconds is seconds since last loop iteration
			video_timer += elapsed_seconds;
			video_dump_timer += elapsed_seconds;
			// only record 10s of video, then quit
			if (video_timer > 10.0) {
				break;
			}
		}
	
		_update_fps_counter (g_window);
		// wipe the drawing surface clear
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport (0, 0, g_gl_width, g_gl_height);
		
		glUseProgram (shader_programme);
		glBindVertexArray (vao);
		// draw points 0-3 from the currently bound VAO with current in-use shader
		glDrawArrays (GL_TRIANGLES, 0, 6);
		// update other events like input handling 
		glfwPollEvents ();
		
		if (GLFW_PRESS == glfwGetKey (g_window, GLFW_KEY_SPACE)) {
			dump_video = true;
		}
		
		// control keys
		bool cam_moved = false;
		if (glfwGetKey (g_window, GLFW_KEY_A)) {
			cam_pos[0] -= cam_speed * elapsed_seconds;
			cam_moved = true;
		}
		if (glfwGetKey (g_window, GLFW_KEY_D)) {
			cam_pos[0] += cam_speed * elapsed_seconds;
			cam_moved = true;
		}
		if (glfwGetKey (g_window, GLFW_KEY_PAGE_UP)) {
			cam_pos[1] += cam_speed * elapsed_seconds;
			cam_moved = true;
		}
		if (glfwGetKey (g_window, GLFW_KEY_PAGE_DOWN)) {
			cam_pos[1] -= cam_speed * elapsed_seconds;
			cam_moved = true;
		}
		if (glfwGetKey (g_window, GLFW_KEY_W)) {
			cam_pos[2] -= cam_speed * elapsed_seconds;
			cam_moved = true;
		}
		if (glfwGetKey (g_window, GLFW_KEY_S)) {
			cam_pos[2] += cam_speed * elapsed_seconds;
			cam_moved = true;
		}
		if (glfwGetKey (g_window, GLFW_KEY_LEFT)) {
			cam_yaw += cam_yaw_speed * elapsed_seconds;
			cam_moved = true;
		}
		if (glfwGetKey (g_window, GLFW_KEY_RIGHT)) {
			cam_yaw -= cam_yaw_speed * elapsed_seconds;
			cam_moved = true;
		}
		// update view matrix
		if (cam_moved) {
			mat4 T = translate (identity_mat4 (), vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); // cam translation
			mat4 R = rotate_y_deg (identity_mat4 (), -cam_yaw); // 
			mat4 view_mat = R * T;
			glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view_mat.m);
		}
		
		
		if (dump_video) { // check if recording mode is enabled
			while (video_dump_timer > frame_time) {
				grab_video_frame (); // 25 Hz so grab a frame
				video_dump_timer -= frame_time;
			}
		}
		if (GLFW_PRESS == glfwGetKey (g_window, GLFW_KEY_ESCAPE)) {
			glfwSetWindowShouldClose (g_window, 1);
		}
		// put the stuff we've been drawing onto the display
		glfwSwapBuffers (g_window);
	}
	
	if (dump_video) {
		dump_video_frames ();
	}
	
	// close GL context and any other GLFW resources
	glfwTerminate();
	return 0;
}