AColMap* a_colmap_new(int Width, int Height, int MaxObjectDim) { AColMap* const m = a_mem_malloc(sizeof(AColMap)); #define nextpow(value) \ ({ \ int p = 0; \ while((1 << p) < value) p++; \ p; \ }) m->bitShift = nextpow(MaxObjectDim); m->w = 1 << a_math_max(0, nextpow(Width) - m->bitShift); m->h = 1 << a_math_max(0, nextpow(Height) - m->bitShift); m->submaps = a_mem_malloc(m->h * sizeof(AList**)); for(int i = m->h; i--; ) { m->submaps[i] = a_mem_malloc(m->w * sizeof(AList*)); for(int j = m->w; j--; ) { m->submaps[i][j] = a_list_new(); } } return m; }
void SpriteGL::Blit(float destx, float desty, float srcx, float srcy, float srcwidth, float srcheight, float destwidth, float destheight) { if(!getImage()) return; if (m_engineCreationTimestamp != g_engine->m_creationTimestamp) { // we need to recreate the texture since the context was invalidated in the meantime buildGLTexture(); } glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); double spriteWidth = nextpow(getWidth()) / m_multiplierx ; double spriteHeight = nextpow(getHeight()) / m_multipliery; //glAlphaFunc(GL_GEQUAL, .80); //glEnable(GL_ALPHA_TEST); if(m_r != 1. || m_g != 1. || m_b != 1.) glColor4f(m_r, m_g, m_b, 1.); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_QUADS); glTexCoord2d((srcx)/spriteWidth, (srcy)/spriteHeight); glVertex2d(destx, desty); glTexCoord2d((srcx)/spriteWidth, (srcy + (srcheight) / m_multipliery )/spriteHeight); glVertex2d(destx, desty + destheight); glTexCoord2d((srcx + (srcwidth) / m_multiplierx)/spriteWidth, (srcy + (srcheight) / m_multipliery)/spriteHeight); glVertex2d(destx + destwidth, desty + destheight); glTexCoord2d((srcx + (srcwidth) / m_multiplierx)/spriteWidth, (srcy) /spriteHeight); glVertex2d(destx + destwidth, desty); glEnd(); if(m_r != 1. || m_g != 1. || m_b != 1.) glColor4f(1.,1.,1., 1.); glPopMatrix(); }