static void render_rectangle_bitmap(PictureBuffer* screen, Vec2 offset,Vec2 dirx,Vec2 diry,Vec2 magnification,Vec4 color)
{
glColor4f(color.r, color.g, color.b, color.a);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
// glColor3f(1,1,0);
// r32 p=0.9f;0
glBindTexture(GL_TEXTURE_2D,(GLuint)screen->handle );
Vec2 lower_left= offset-(dirx*(r32)screen->width*magnification.x+diry*(r32)screen->height*magnification.y)*0.5f;
Vec2 upper_left= offset-(dirx*(r32)screen->width*magnification.x-diry*(r32)screen->height*magnification.y)*0.5f;
Vec2 upper_right= offset+(dirx*(r32)screen->width*magnification.x+diry*(r32)screen->height*magnification.y)*0.5f;
Vec2 lower_right= offset+(dirx*(r32)screen->width*magnification.x-diry*(r32)screen->height*magnification.y)*0.5f;
glBegin(GL_TRIANGLES);//<--26% of the global time goes here
glTexCoord2f(0,1);
glVertex2f(upper_left.x,upper_left.y);
glTexCoord2f(1,1);
glVertex2f(upper_right.x,upper_right.y);
glTexCoord2f(1,0);
glVertex2f(lower_right.x,lower_right.y);
glTexCoord2f(0,1);
glVertex2f(upper_left.x,upper_left.y);
glTexCoord2f(1,0);
glVertex2f(lower_right.x,lower_right.y);
glTexCoord2f(0,0);
glVertex2f(lower_left.x,lower_left.y);
glEnd();
glBindTexture(GL_TEXTURE_2D,0 );//<--36% of the global time goes here
}
static void prepare_using_bitmap(PictureBuffer* screen)
{
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glGenTextures(1,(GLuint*)&screen->handle);
glBindTexture(GL_TEXTURE_2D,(GLuint)screen->handle );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST );
//this is for the sprite art, this is not for regular art
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP );
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,screen->width,screen->height, 0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,screen->picture);
glBindTexture(GL_TEXTURE_2D,0 );
}
void initOpengl(HWND window)
{
HDC hdc=GetDC(window);
PIXELFORMATDESCRIPTOR wanted_format= {};
wanted_format.nSize=sizeof(PIXELFORMATDESCRIPTOR);
wanted_format.nVersion=1;
wanted_format.dwFlags=PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW|PFD_DOUBLEBUFFER;
wanted_format.iPixelType=PFD_TYPE_RGBA;
wanted_format.cColorBits=24;
wanted_format.cAlphaBits=8;
int returned_index=ChoosePixelFormat(hdc,&wanted_format);
PIXELFORMATDESCRIPTOR returned_format= {};
DescribePixelFormat(hdc, returned_index,sizeof(PIXELFORMATDESCRIPTOR), &returned_format);
SetPixelFormat(hdc,returned_index,&returned_format);
HGLRC hglrc = wglCreateContext(hdc);
Assert(wglMakeCurrent(hdc,hglrc));
ReleaseDC(window, hdc);
}