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

📄 gameswf_render_handler_xbox.cpp

📁 一个开源的Flash 播放器,可以在Windows/Linux 上运行
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	//	// Munges *data (in order to make mipmaps)!!	{		assert(bi);		bi->set_alpha_image(w, h, data);	}	void	delete_bitmap_info(gameswf::bitmap_info* bi)	// Delete the given bitmap info struct.	{		delete bi;	}	void	begin_display(		gameswf::rgba background_color,		int viewport_x0, int viewport_y0,		int viewport_width, int viewport_height,		float x0, float x1, float y0, float y1)	// Set up to render a full frame from a movie and fills the	// background.	Sets up necessary transforms, to scale the	// movie to fit within the given dimensions.  Call	// end_display() when you're done.	//	// The rectangle (viewport_x0, viewport_y0, viewport_x0 +	// viewport_width, viewport_y0 + viewport_height) defines the	// window coordinates taken up by the movie.	//	// The rectangle (x0, y0, x1, y1) defines the pixel	// coordinates of the movie that correspond to the viewport	// bounds.	{// 		// Matrix setup// 		D3DXMATRIX	ortho;// 		D3DXMatrixOrthoOffCenterRH(&ortho, x0, x1, y0, y1, 0.0f, 1.0f);// 		IDirect3DDevice8::SetTransform(D3DTS_PROJECTION, &ortho);// 		D3DXMATRIX	ident;// 		D3DXMatrixIdentity(&ident);// 		IDirect3DDevice8::SetTransform(D3DTS_VIEW, &ident);// 		// IDirect3DDevice8::SetTransform(D3DTS_WORLD, &ident);// 		// etc.?		// Viewport.		D3DVIEWPORT8	vp;		vp.X = viewport_x0;		vp.Y = viewport_y0;		vp.Width = viewport_width;		vp.Height = viewport_height;		vp.MinZ = 0.0f;		vp.MaxZ = 0.0f;		IDirect3DDevice8::SetViewport(&vp);		// Matrix to map from SWF movie (TWIPs) coords to		// viewport coordinates.		float	dx = x1 - x0;		float	dy = y1 - y0;		if (dx < 1) { dx = 1; }		if (dy < 1) { dy = 1; }		m_viewport_matrix.set_identity();		m_viewport_matrix.m_[0][0] = viewport_width / dx;		m_viewport_matrix.m_[1][1] = viewport_height / dy;		m_viewport_matrix.m_[0][2] = viewport_x0 - m_viewport_matrix.m_[0][0] * x0;		m_viewport_matrix.m_[1][2] = viewport_y0 - m_viewport_matrix.m_[1][1] * y0;		// Blending renderstates		IDirect3DDevice8::SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);		IDirect3DDevice8::SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);		IDirect3DDevice8::SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);		// Textures off by default.		IDirect3DDevice8::SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);		// @@ for sanity's sake, let's turn of backface culling...		IDirect3DDevice8::SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);//xxxxx		IDirect3DDevice8::SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);	//xxxxx		// Vertex format.		IDirect3DDevice8::SetVertexShader(s_vshader_handle);		// No pixel shader.		IDirect3DDevice8::SetPixelShaderProgram(NULL);#if 0		glViewport(viewport_x0, viewport_y0, viewport_width, viewport_height);		glMatrixMode(GL_MODELVIEW);		glPushMatrix();		glOrtho(x0, x1, y0, y1, -1, 1);		glEnable(GL_BLEND);		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);	// GL_MODULATE		glDisable(GL_TEXTURE_2D);#endif // 0		// Clear the background, if background color has alpha > 0.		if (background_color.m_a > 0)		{			// @@ for testing			static int	bobo = 0;			IDirect3DDevice8::Clear(				0,				NULL,				D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,				bobo += 5,				0.0f,				0);			// Draw a big quad.			apply_color(background_color);			set_matrix(gameswf::matrix::identity);			apply_matrix(m_current_matrix);			IDirect3DDevice8::Begin(D3DPT_TRIANGLESTRIP);			IDirect3DDevice8::SetVertexData2f(D3DVSDE_POSITION, x0, y0);			IDirect3DDevice8::SetVertexData2f(D3DVSDE_POSITION, x1, y0);			IDirect3DDevice8::SetVertexData2f(D3DVSDE_POSITION, x1, y1);			IDirect3DDevice8::SetVertexData2f(D3DVSDE_POSITION, x0, y1);			IDirect3DDevice8::End();#if 0			glBegin(GL_QUADS);			glVertex2f(x0, y0);			glVertex2f(x1, y0);			glVertex2f(x1, y1);			glVertex2f(x0, y1);			glEnd();#endif // 0		}	}	void	end_display()	// Clean up after rendering a frame.  Client program is still	// responsible for calling glSwapBuffers() or whatever.	{#if 0		glMatrixMode(GL_MODELVIEW);		glPopMatrix();#endif // 0	}	void	set_matrix(const gameswf::matrix& m)	// Set the current transform for mesh & line-strip rendering.	{		m_current_matrix = m;	}	void	set_cxform(const gameswf::cxform& cx)	// Set the current color transform for mesh & line-strip rendering.	{		m_current_cxform = cx;	}		void	apply_matrix(const gameswf::matrix& mat_in)	// Set the given transformation matrix.	{		gameswf::matrix	m(m_viewport_matrix);		m.concatenate(mat_in);		float	row0[4];		float	row1[4];		row0[0] = m.m_[0][0];		row0[1] = m.m_[0][1];		row0[2] = 0;		row0[3] = m.m_[0][2];		row1[0] = m.m_[1][0];		row1[1] = m.m_[1][1];		row1[2] = 0;		row1[3] = m.m_[1][2];//		glMultMatrixf(mat);//		IDirect3DDevice8::SetTransform(D3DTS_VIEW, (D3DMATRIX*) &mat[0]);		IDirect3DDevice8::SetVertexShaderConstant(0, row0, 1);		IDirect3DDevice8::SetVertexShaderConstant(1, row1, 1);	}	static void	apply_color(const gameswf::rgba& c)	// Set the given color.	{//		glColor4ub(c.m_r, c.m_g, c.m_b, c.m_a);		IDirect3DDevice8::SetVertexData4ub(D3DVSDE_DIFFUSE, c.m_r, c.m_g, c.m_b, c.m_a);	}	void	fill_style_disable(int fill_side)	// Don't fill on the {0 == left, 1 == right} side of a path.	{		assert(fill_side >= 0 && fill_side < 2);		m_current_styles[fill_side].disable();	}	void	line_style_disable()	// Don't draw a line on this path.	{		m_current_styles[LINE_STYLE].disable();	}	void	fill_style_color(int fill_side, gameswf::rgba color)	// Set fill style for the left interior of the shape.  If	// enable is false, turn off fill for the left interior.	{		assert(fill_side >= 0 && fill_side < 2);		m_current_styles[fill_side].set_color(m_current_cxform.transform(color));	}	void	line_style_color(gameswf::rgba color)	// Set the line style of the shape.  If enable is false, turn	// off lines for following curve segments.	{		m_current_styles[LINE_STYLE].set_color(m_current_cxform.transform(color));	}	void	fill_style_bitmap(int fill_side, const gameswf::bitmap_info* bi, const gameswf::matrix& m, bitmap_wrap_mode wm)	{		assert(fill_side >= 0 && fill_side < 2);		m_current_styles[fill_side].set_bitmap(bi, m, wm, m_current_cxform);	}		void	line_style_width(float width)	{		// WK: what to do here???	}	void	draw_mesh_strip(const void* coords, int vertex_count)	{		// Set up current style.		m_current_styles[LEFT_STYLE].apply();		apply_matrix(m_current_matrix);		// @@ we'd like to use a VB instead, and use DrawPrimitive().		// Draw the mesh.		IDirect3DDevice8::DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, vertex_count - 2, coords, sizeof(Sint16) * 2);		if (m_current_styles[LEFT_STYLE].needs_second_pass())		{			// 2nd pass, if necessary.			m_current_styles[LEFT_STYLE].apply_second_pass();			IDirect3DDevice8::DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, vertex_count - 2, coords, sizeof(Sint16) * 2);			m_current_styles[LEFT_STYLE].cleanup_second_pass();		}#if 0		glMatrixMode(GL_MODELVIEW);		glPushMatrix();		apply_matrix(m_current_matrix);		// Send the tris to OpenGL		glEnableClientState(GL_VERTEX_ARRAY);		glVertexPointer(2, GL_SHORT, sizeof(Sint16) * 2, coords);		glDrawArrays(GL_TRIANGLE_STRIP, 0, vertex_count);		if (m_current_styles[LEFT_STYLE].needs_second_pass())		{			m_current_styles[LEFT_STYLE].apply_second_pass();			glDrawArrays(GL_TRIANGLE_STRIP, 0, vertex_count);			m_current_styles[LEFT_STYLE].cleanup_second_pass();		}		glDisableClientState(GL_VERTEX_ARRAY);		glPopMatrix();#endif // 0	}	void	draw_line_strip(const void* coords, int vertex_count)	// Draw the line strip formed by the sequence of points.	{		// Set up current style.		m_current_styles[LINE_STYLE].apply();		apply_matrix(m_current_matrix);		IDirect3DDevice8::DrawPrimitiveUP(D3DPT_LINESTRIP, vertex_count - 1, coords, sizeof(Sint16) * 2);	}	void	draw_bitmap(		const gameswf::matrix& m,		const gameswf::bitmap_info* bi,		const gameswf::rect& coords,		const gameswf::rect& uv_coords,		gameswf::rgba color)	// Draw a rectangle textured with the given bitmap, with the	// given color.	 Apply given transform; ignore any currently	// set transforms.	//	// Intended for textured glyph rendering.	{		assert(bi);		apply_color(color);		gameswf::point a, b, c, d;		m.transform(&a, gameswf::point(coords.m_x_min, coords.m_y_min));		m.transform(&b, gameswf::point(coords.m_x_max, coords.m_y_min));		m.transform(&c, gameswf::point(coords.m_x_min, coords.m_y_max));		d.m_x = b.m_x + c.m_x - a.m_x;		d.m_y = b.m_y + c.m_y - a.m_y;		// Set texture.		IDirect3DDevice8::SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);		IDirect3DDevice8::SetTexture(0, s_d3d_textures[bi->m_texture_id]);		// @@ TODO this is wrong; needs fixing!  Options:		//		// * compute texgen parameters for the bitmap		//		// * change to a vshader which passes the texcoords through		// No texgen; just pass through.		float	row0[4] = { 1, 0, 0, 0 };		float	row1[4] = { 0, 1, 0, 0 };		IDirect3DDevice8::SetVertexShaderConstant(4, row0, 1);		IDirect3DDevice8::SetVertexShaderConstant(5, row1, 1);		// Draw the quad.		IDirect3DDevice8::Begin(D3DPT_TRIANGLESTRIP);				IDirect3DDevice8::SetVertexData2f(D3DVSDE_TEXCOORD0, uv_coords.m_x_min, uv_coords.m_y_min);		IDirect3DDevice8::SetVertexData4f(D3DVSDE_VERTEX, a.m_x, a.m_y, 0, 1);		IDirect3DDevice8::SetVertexData2f(D3DVSDE_TEXCOORD0, uv_coords.m_x_max, uv_coords.m_y_min);		IDirect3DDevice8::SetVertexData4f(D3DVSDE_VERTEX, b.m_x, b.m_y, 0, 1);		IDirect3DDevice8::SetVertexData2f(D3DVSDE_TEXCOORD0, uv_coords.m_x_min, uv_coords.m_y_max);		IDirect3DDevice8::SetVertexData4f(D3DVSDE_VERTEX, c.m_x, c.m_y, 0, 1);		IDirect3DDevice8::SetVertexData2f(D3DVSDE_TEXCOORD0, uv_coords.m_x_max, uv_coords.m_y_max);		IDirect3DDevice8::SetVertexData4f(D3DVSDE_VERTEX, d.m_x, d.m_y, 0, 1);		IDirect3DDevice8::End();#if 0		glBindTexture(GL_TEXTURE_2D, bi->m_texture_id);		glEnable(GL_TEXTURE_2D);		glDisable(GL_TEXTURE_GEN_S);		glDisable(GL_TEXTURE_GEN_T);		glBegin(GL_TRIANGLE_STRIP);		glTexCoord2f(uv_coords.m_x_min, uv_coords.m_y_min);		glVertex2f(a.m_x, a.m_y);		glTexCoord2f(uv_coords.m_x_max, uv_coords.m_y_min);		glVertex2f(b.m_x, b.m_y);		glTexCoord2f(uv_coords.m_x_min, uv_coords.m_y_max);		glVertex2f(c.m_x, c.m_y);		glTexCoord2f(uv_coords.m_x_max, uv_coords.m_y_max);		glVertex2f(d.m_x, d.m_y);		glEnd();#endif // 0	}		void begin_submit_mask()	{#if 0		glEnable(GL_STENCIL_TEST); 		glClearStencil(0);		glClear(GL_STENCIL_BUFFER_BIT);		glColorMask(0,0,0,0);	// disable framebuffer writes		glEnable(GL_STENCIL_TEST);	// enable stencil buffer for "marking" the mask		glStencilFunc(GL_ALWAYS, 1, 1);	// always passes, 1 bit plane, 1 as mask		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);	// we set the stencil buffer to 1 where we draw any polygon							// keep if test fails, keep if test passes but buffer test fails							// replace if test passes #endif // 0	}		void end_submit_mask()	{#if 0		glColorMask(1,1,1,1);	// enable framebuffer writes		glStencilFunc(GL_EQUAL, 1, 1);	// we draw only where the stencil is 1 (where the mask was drawn)		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);	// don't change the stencil buffer	  #endif // 0	}		void disable_mask()	{#if 0	    glDisable(GL_STENCIL_TEST); 

⌨️ 快捷键说明

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