void gr_fill(int x, int y, int w, int h) { GGLContext *gl = gr_context; if(gr_is_curr_clr_opaque) gl->disable(gl, GGL_BLEND); gl->disable(gl, GGL_TEXTURE_2D); gl->recti(gl, x, y, x + w, y + h); if(gr_is_curr_clr_opaque) gl->enable(gl, GGL_BLEND); }
void gr_buffertest() { GGLContext *gr_context = 0; gglInit(&gr_context); GGLContext *gl = gr_context; gr_mem_surface2.data = NULL; get_memory_surface(&gr_mem_surface2); gl->colorBuffer(gl, &gr_mem_surface2); unsigned int r = 0; unsigned int g = 255; unsigned int b = 0; unsigned int a = 255; GGLint color[4]; color[0] = ((r << 8) | r) + 1; color[1] = ((g << 8) | g) + 1; color[2] = ((b << 8) | b) + 1; color[3] = ((a << 8) | a) + 1; #ifdef COLORS_REVERSED color[0] = ((b << 8) | b) + 1; color[2] = ((r << 8) | r) + 1; #endif gl->color4xv(gl, color); gl->disable(gl, GGL_TEXTURE_2D); gl->recti(gl, 150, 150, 300, 300); }
void gr_fill(int x1, int y1, int x2, int y2) { x1 += overscan_offset_x; y1 += overscan_offset_y; x2 += overscan_offset_x; y2 += overscan_offset_y; GGLContext *gl = gr_context; gl->disable(gl, GGL_TEXTURE_2D); gl->recti(gl, x1, y1, x2, y2); }
void gr_fill(int x, int y, int w, int h) { GGLContext *gl = gr_context; x += overscan_offset_x; y += overscan_offset_y; w += overscan_offset_x; h += overscan_offset_y; //fprintf(stderr, "gr_fill: x=%d,y=%d,w=%d,h=%d\n", x, y, w, h); gl->disable(gl, GGL_TEXTURE_2D); gl->recti(gl, x, y, w, h); }
void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy) { if (gr_context == NULL) { return; } GGLContext *gl = gr_context; GGLSurface *surface = (GGLSurface*)source; if(surface->format == GGL_PIXEL_FORMAT_RGBX_8888) gl->disable(gl, GGL_BLEND); gl->bindTexture(gl, surface); gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); gl->enable(gl, GGL_TEXTURE_2D); gl->texCoord2i(gl, sx - dx, sy - dy); gl->recti(gl, dx, dy, dx + w, dy + h); gl->disable(gl, GGL_TEXTURE_2D); if(surface->format == GGL_PIXEL_FORMAT_RGBX_8888) gl->enable(gl, GGL_BLEND); }
void gr_line(int x0, int y0, int x1, int y1, int width) { GGLContext *gl = gr_context; if(gr_is_curr_clr_opaque) gl->disable(gl, GGL_BLEND); const int coords0[2] = { x0 << 4, y0 << 4 }; const int coords1[2] = { x1 << 4, y1 << 4 }; gl->linex(gl, coords0, coords1, width << 4); if(gr_is_curr_clr_opaque) gl->enable(gl, GGL_BLEND); }
int gr_textExWH(int x, int y, const char *s, void* pFont, int max_width, int max_height) { GGLContext *gl = gr_context; GRFont *font = (GRFont*) pFont; unsigned off; unsigned cwidth; int rect_x, rect_y; /* Handle default font */ if (!font) font = gr_font; #ifndef TW_DISABLE_TTF if(font->type == FONT_TYPE_TTF) return gr_ttf_textExWH(gl, x, y, s, pFont, max_width, max_height); #endif gl->bindTexture(gl, &font->texture); gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); gl->enable(gl, GGL_TEXTURE_2D); while((off = *s++)) { off -= 32; cwidth = 0; if (off < 96) { cwidth = font->offset[off+1] - font->offset[off]; if ((x + (int)cwidth) < max_width) rect_x = x + cwidth; else rect_x = max_width; if (y + font->cheight < (unsigned int)(max_height)) rect_y = y + font->cheight; else rect_y = max_height; gl->texCoord2i(gl, (font->offset[off]) - x, 0 - y); gl->recti(gl, x, y, rect_x, rect_y); x += cwidth; if (x > max_width) return x; } } gl->disable(gl, GGL_TEXTURE_2D); return x; }
// Scale image function int res_scale_surface(gr_surface source, gr_surface* destination, float scale_w, float scale_h) { GGLContext *gl = NULL; GGLSurface* sc_mem_surface = NULL; *destination = NULL; GGLSurface *surface = (GGLSurface*)source; int w = gr_get_width(source), h = gr_get_height(source); int sx = 0, sy = 0, dx = 0, dy = 0; float dw = (float)w * scale_w; float dh = (float)h * scale_h; // Create a new surface that is the appropriate size sc_mem_surface = init_display_surface((int)dw, (int)dh); if (!sc_mem_surface) { printf("gr_scale_surface failed to init_display_surface\n"); return -1; } sc_mem_surface->format = surface->format; // Initialize the context gglInit(&gl); gl->colorBuffer(gl, sc_mem_surface); gl->activeTexture(gl, 0); // Enable or disable blending based on source surface format if (surface->format == GGL_PIXEL_FORMAT_RGBX_8888) { gl->disable(gl, GGL_BLEND); } else { gl->enable(gl, GGL_BLEND); gl->blendFunc(gl, GGL_ONE, GGL_ZERO); } // Bind our source surface to the context gl->bindTexture(gl, surface); // Deal with the scaling gl->texParameteri(gl, GGL_TEXTURE_2D, GGL_TEXTURE_MIN_FILTER, GGL_LINEAR); gl->texParameteri(gl, GGL_TEXTURE_2D, GGL_TEXTURE_MAG_FILTER, GGL_LINEAR); gl->texParameteri(gl, GGL_TEXTURE_2D, GGL_TEXTURE_WRAP_S, GGL_CLAMP); gl->texParameteri(gl, GGL_TEXTURE_2D, GGL_TEXTURE_WRAP_T, GGL_CLAMP); gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_AUTOMATIC); gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_AUTOMATIC); gl->enable(gl, GGL_TEXTURE_2D); int32_t grad[8]; memset(grad, 0, sizeof(grad)); // s, dsdx, dsdy, scale, t, dtdx, dtdy, tscale <- this is wrong! // This api uses block floating-point for S and T texture coordinates. // All values are given in 16.16, scaled by 'scale'. In other words, // set scale to 0, for 16.16 values. // s, dsdx, dsdy, t, dtdx, dtdy, sscale, tscale float dsdx = (float)w / dw; float dtdy = (float)h / dh; grad[0] = ((float)sx - (dsdx * dx)) * 65536; grad[1] = dsdx * 65536; grad[3] = ((float)sy - (dtdy * dy)) * 65536; grad[5] = dtdy * 65536; // printf("blit: w=%d h=%d dx=%d dy=%d dw=%f dh=%f dsdx=%f dtdy=%f s0=%x dsdx=%x t0=%x dtdy=%x\n", // w, h, dx, dy, dw, dh, dsdx, dtdy, grad[0], grad[1], grad[3], grad[5]); gl->texCoordGradScale8xv(gl, 0 /*tmu*/, grad); // draw / scale the source surface to our target context gl->recti(gl, dx, dy, dx + dw, dy + dh); gglUninit(gl); gl = NULL; // put the scaled surface in our destination *destination = (gr_surface*) sc_mem_surface; // free memory used in the source res_free_surface(source); source = NULL; return 0; }
void gr_fill(int x, int y, int w, int h) { GGLContext *gl = gr_context; gl->disable(gl, GGL_TEXTURE_2D); gl->recti(gl, x, y, w, h); }
void gr_fill_l(int x, int y, int w, int h) { GGLContext *gl = gr_context; gl->disable(gl, GGL_TEXTURE_2D); gl->recti(gl, gr_fb_width() - h, x, gr_fb_width() - y, w); }
void gr_noclip() { GGLContext *gl = gr_context; gl->scissor(gl, 0, 0, gr_fb_width(), gr_fb_height()); gl->disable(gl, GGL_SCISSOR_TEST); }