void XeDrawSurface2(struct XenosSurface *txt, float dstx, float dsty, float width, float height, int withalpha) { float uleft = 0, uright = 1, vtop = 0, vbottom = 1; float logo[] = { dstx, dsty + height, uleft, vtop, dstx + width, dsty + height, uright, vtop, dstx, dsty, uleft, vbottom, dstx, dsty, uleft, vbottom, dstx + width, dsty + height, uright, vtop, dstx + width, dsty, uright, vbottom }; Xe_VBBegin(xe, 4); Xe_VBPut(xe, logo, 6 * 4); struct XenosVertexBuffer *vb = Xe_VBEnd(xe); Xe_VBPoolAdd(xe, vb); if (withalpha) { Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA); Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } else { Xe_SetSrcBlend(xe, XE_BLEND_ONE); Xe_SetDestBlend(xe, XE_BLEND_ZERO); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } Xe_SetShader(xe, SHADER_TYPE_PIXEL, sh_text_ps, 0); Xe_SetShader(xe, SHADER_TYPE_VERTEX, sh_text_vs, 0); Xe_SetTexture(xe, 0, txt); Xe_Draw(xe, vb, 0); }
void XenonGLDisplay() { Xe_SetBlendOp(xe, XE_BLENDOP_ADD); Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA); Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA); // update vb cache !!! Xe_VB_Lock(xe, pVbGL, 0, XE_MAX_VERTICES, XE_LOCK_WRITE); Xe_VB_Unlock(xe, pVbGL); /* // Refresh texture cash unsigned int * pBitmap = Xe_Surface_LockRect(xe, pVideoSurface, 0, 0, 0, 0, XE_LOCK_WRITE); int i; for(i = 0;i<(vid.width*vid.height);i++) { //Make an ARGB bitmap unsigned int c = (pQ2Palette[vid.buffer[i]]) >> 8 | ( 0xFF << 24 ); pBitmap[i] = c; } Xe_Surface_Unlock(xe, pVideoSurface); // Select stream and shaders Xe_SetTexture(xe, 0, pVideoSurface); Xe_SetCullMode(xe, XE_CULL_NONE); Xe_SetStreamSource(xe, 0, pVBSw, 0, 10); Xe_SetShader(xe, SHADER_TYPE_PIXEL, pPixelShader, 0); Xe_SetShader(xe, SHADER_TYPE_VERTEX, pVertexShader, 0); // Draw Xe_DrawPrimitive(xe, XE_PRIMTYPE_RECTLIST, 0, 1); */ // Resolve Xe_Resolve(xe); while(!Xe_IsVBlank(xe)); Xe_Sync(xe); // Reset states Xe_InvalidateState(xe); Xe_SetClearColor(xe, 0); xe_NumVerts = xe_PrevNumVerts = 0; ShowFPS(); }
//Garde l'aspect ratio :) en function de la texture et non du framebuffer void XeDrawSurface(struct XenosSurface *txt, float dstx, float dsty, float scale, int withalpha,int center) { float scrratio = ((float) xe->tex_fb.width / (float) xe->tex_fb.height); //float txtratio=((float)txt->width/(float)txt->height); float height = scale * scrratio; float width = scale; float uleft = 0, uright = 1, vtop = 0, vbottom = 1; dsty=dsty - ((height/2)*center); float logo[] = { dstx, dsty + height, uleft, vtop, dstx + width, dsty + height, uright, vtop, dstx, dsty, uleft, vbottom, dstx, dsty, uleft, vbottom, dstx + width, dsty + height, uright, vtop, dstx + width, dsty, uright, vbottom }; Xe_VBBegin(xe, 4); Xe_VBPut(xe, logo, 6 * 4); struct XenosVertexBuffer *vb = Xe_VBEnd(xe); Xe_VBPoolAdd(xe, vb); if (withalpha) { Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA); Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } else { Xe_SetSrcBlend(xe, XE_BLEND_ONE); Xe_SetDestBlend(xe, XE_BLEND_ZERO); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } Xe_SetShader(xe, SHADER_TYPE_PIXEL, sh_text_ps, 0); Xe_SetShader(xe, SHADER_TYPE_VERTEX, sh_text_vs, 0); Xe_SetTexture(xe, 0, txt); Xe_Draw(xe, vb, 0); }
void XePrintf(float dstx, float dsty, const char *text, float scale, uint32_t icolor) { if (!*text) return 0; Xe_VBBegin(xe, 5); while (*text) { //struct fontentry *f = &fontentries[(unsigned char)*text++]; struct fnt_s *f = &verdana_fnt[(unsigned char) *text++]; if (!f->width) continue; float u = f->x / WH; float v = f->y / WH; float uw = f->width / WH; float vw = f->height / WH; float width = uw * scale, height = vw * scale; float xo = f->xoffset / WH * scale; float yo = f->yoffset / WH* scale; float left = dstx + xo, top = dsty - yo, right = dstx + width, bottom = dsty - yo - height; union { float color; int icolor; } un; un.icolor = icolor; float color = un.color; float letter[] = { left, top, u, v, color, right, top, u + uw, v, color, left, bottom, u, v + vw, color, left, bottom, u, v + vw, color, right, top, u + uw, v, color, right, bottom, u + uw, v + vw, color, }; Xe_VBPut(xe, letter, 6 * 5); dstx += f->xadvance / WH * scale; } struct XenosVertexBuffer *vb = Xe_VBEnd(xe); Xe_VBPoolAdd(xe, vb); Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA); Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); Xe_SetShader(xe, SHADER_TYPE_PIXEL, sh_font_ps, 0); Xe_SetShader(xe, SHADER_TYPE_VERTEX, sh_font_vs, 0); Xe_SetTexture(xe, 0, XeFont); Xe_Draw(xe, vb, 0); return dstx; }
static void draw_quad(render_primitive *prim) { void * texture = (prim->texture.base); //void Xe_SetBlendControl(struct XenosDevice *xe, int col_src, int col_op, int col_dst, int alpha_src, int alpha_op, int alpha_dst); switch (PRIMFLAG_GET_BLENDMODE(prim->flags)) { case BLENDMODE_NONE: Xe_SetAlphaTestEnable(g_pVideoDevice,0); Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD); Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_SRCALPHA); Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_INVSRCALPHA); break; case BLENDMODE_ALPHA: Xe_SetAlphaTestEnable(g_pVideoDevice,1); Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD); Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_SRCALPHA); Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_INVSRCALPHA); break; case BLENDMODE_RGB_MULTIPLY: Xe_SetAlphaTestEnable(g_pVideoDevice,1); Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD); Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_DESTCOLOR); Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_ZERO); break; case BLENDMODE_ADD: Xe_SetAlphaTestEnable(g_pVideoDevice,1); Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD); Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_SRCALPHA); Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_ONE); break; } DrawVerticeFormats *vertex = (DrawVerticeFormats *) Xe_VB_Lock(g_pVideoDevice, vb, nb_vertices, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE); memset(vertex, 0, 3 * sizeof (DrawVerticeFormats)); { vertex[0].x = prim->bounds.x0 - 0.5f; vertex[0].y = prim->bounds.y0 - 0.5f; vertex[1].x = prim->bounds.x1 - 0.5f; vertex[1].y = prim->bounds.y0 - 0.5f; vertex[2].x = prim->bounds.x0 - 0.5f; vertex[2].y = prim->bounds.y1 - 0.5f; vertex[3].x = prim->bounds.x1 - 0.5f; vertex[3].y = prim->bounds.y1 - 0.5f; // set the texture coordinates if (texture != NULL) { vertex[0].u = prim->texcoords.tl.u; vertex[0].v = prim->texcoords.tl.v; vertex[1].u = prim->texcoords.tr.u; vertex[1].v = prim->texcoords.tr.v; vertex[2].u = prim->texcoords.bl.u; vertex[2].v = prim->texcoords.bl.v; vertex[3].u = prim->texcoords.br.u; vertex[3].v = prim->texcoords.br.v; n++; } XeColor color; color.r = (prim->color.r * 255.0f); color.g = (prim->color.g * 255.0f); color.b = (prim->color.b * 255.0f); color.a = (prim->color.a * 255.0f); int i = 0; for (i = 0; i < 3; i++) { vertex[i].z = 0.0; vertex[i].w = 1.0; } } Xe_VB_Unlock(g_pVideoDevice, vb); Xe_SetStreamSource(g_pVideoDevice, 0, vb, nb_vertices, sizeof (DrawVerticeFormats)); Xe_DrawPrimitive(g_pVideoDevice, XE_PRIMTYPE_RECTLIST, 0, 1); nb_vertices += 256; }