Example #1
0
static Uint8 SetFullscreen(GPU_Renderer* renderer, Uint8 enable_fullscreen, Uint8 use_desktop_resolution)
{
    GPU_Target* target = renderer->current_context_target;
    
    // These values should actually come from the window
    Uint8 was_fullscreen = !enable_fullscreen;
    Uint8 is_fullscreen = enable_fullscreen;
    
    GPU_Log(" %s (dummy)\n", __func__);
    
    //if(SetWindowFullscreen(target->context->windowID, enable_fullscreen) >= 0)
    {
        // If we just went fullscreen, save the original resolution
        // We do this because you can't depend on the resolution to be preserved by SDL
        // SDL_WINDOW_FULLSCREEN_DESKTOP changes the resolution and SDL_WINDOW_FULLSCREEN can change it when a given mode is not available
        if(!was_fullscreen && is_fullscreen)
        {
            target->context->stored_window_w = target->context->window_w;
            target->context->stored_window_h = target->context->window_h;
        }
        
        // If we're in windowed mode now and a resolution was stored, restore the original window resolution
        if(was_fullscreen && !is_fullscreen && (target->context->stored_window_w != 0 && target->context->stored_window_h != 0))
            SDL_SetWindowSize(SDL_GetWindowFromID(target->context->windowID), target->context->stored_window_w, target->context->stored_window_h);
        
        // Update window dims
        SDL_GetWindowSize(SDL_GetWindowFromID(target->context->windowID), &target->context->window_w, &target->context->window_h);
    }

    if(is_fullscreen != was_fullscreen)
    {
        // If virtual res is not set, we need to update the target dims and reset stuff that no longer is right
        if(!target->using_virtual_resolution)
        {
            // Update dims
            target->w = target->context->window_w;
            target->h = target->context->window_h;
        }

        // Reset viewport
        target->viewport = GPU_MakeRect(0, 0, target->context->window_w, target->context->window_h);
        // Update viewport here
        
        // Reset clip
        GPU_UnsetClip(target);
        
        // Update camera here
    }
    
    target->base_w = target->context->window_w;
    target->base_h = target->context->window_h;
    
    return is_fullscreen;
}
Example #2
0
static GPU_Target* LoadTarget(GPU_Renderer* renderer, GPU_Image* image)
{
	GPU_Target* result;
	
    GPU_Log(" %s (dummy)\n", __func__);
    
    if(image == NULL)
        return NULL;

    if(image->target != NULL)
    {
        image->target->refcount++;
        return image->target;
    }

    if(!(renderer->enabled_features & GPU_FEATURE_RENDER_TARGETS))
        return NULL;

    result = (GPU_Target*)malloc(sizeof(GPU_Target));
    memset(result, 0, sizeof(GPU_Target));
    result->refcount = 1;
    result->data = NULL;  // Allocate a data structure as needed for other render target data
    
    result->renderer = renderer;
    result->context = NULL;
    result->image = image;
    result->w = image->w;
    result->h = image->h;
    result->base_w = image->texture_w;
    result->base_h = image->texture_h;
    
    result->viewport = GPU_MakeRect(0, 0, result->w, result->h);
    
    result->camera = GPU_GetDefaultCamera();
    
    result->use_clip_rect = 0;
    result->clip_rect.x = 0;
    result->clip_rect.y = 0;
    result->clip_rect.w = result->w;
    result->clip_rect.h = result->h;
    result->use_color = 0;

    image->target = result;
    return result;
}
Example #3
0
static GPU_Target* CreateTargetFromWindow(GPU_Renderer* renderer, Uint32 windowID, GPU_Target* target)
{
    GPU_Log(" %s (dummy)\n", __func__);
    
    if(target == NULL)
    {
        target = (GPU_Target*)malloc(sizeof(GPU_Target));
        memset(target, 0, sizeof(GPU_Target));
        
        target->refcount = 1;
        target->is_alias = 0;
        target->data = NULL;  // Allocate a data structure as needed for other render target data
        target->image = NULL;
        
        target->context = (GPU_Context*)malloc(sizeof(GPU_Context));
        memset(target->context, 0, sizeof(GPU_Context));
        
        target->context->windowID = windowID;
        target->context->data = NULL;  // Allocate a data structure as needed for other context data
        target->context->context = NULL;
    }
    else
    {
        GPU_RemoveWindowMapping(target->context->windowID);
    }
    
    // This is used for restoring window after fullscreen switches
    SDL_GetWindowSize(SDL_GetWindowFromID(target->context->windowID), &target->context->window_w, &target->context->window_h);
    target->context->stored_window_w = target->context->window_w;
    target->context->stored_window_h = target->context->window_h;
    
    GPU_AddWindowMapping(target);
    
    
    target->renderer = renderer;
    target->w = target->context->window_w;
    target->h = target->context->window_h;
    target->base_w = target->context->window_w;
    target->base_h = target->context->window_h;

    target->use_clip_rect = 0;
    target->clip_rect.x = 0;
    target->clip_rect.y = 0;
    target->clip_rect.w = target->w;
    target->clip_rect.h = target->h;
    target->use_color = 0;
    
    target->viewport = GPU_MakeRect(0, 0, target->context->window_w, target->context->window_h);
    target->camera = GPU_GetDefaultCamera();
    
    target->context->line_thickness = 1.0f;
    target->context->use_texturing = 1;
    target->context->shapes_use_blending = 1;
    target->context->shapes_blend_mode = GPU_GetBlendModeFromPreset(GPU_BLEND_NORMAL);
    
    target->context->projection_matrix.size = 1;
    GPU_MatrixIdentity(target->context->projection_matrix.matrix[0]);
    
    target->context->modelview_matrix.size = 1;
    GPU_MatrixIdentity(target->context->modelview_matrix.matrix[0]);
    
    target->context->matrix_mode = GPU_MODELVIEW;
    
    
    renderer->impl->SetLineThickness(renderer, 1.0f);
    
    
    target->context->default_textured_shader_program = 0;
    target->context->default_untextured_shader_program = 0;
    target->context->current_shader_program = 0;
    
    return target;
}
Example #4
0
int main(int argc, char* argv[])
{
	GPU_Target* screen;

	printRenderers();
	
	screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS);
	if(screen == NULL)
		return -1;
	
	printCurrentRenderer();

	{
		GPU_Image* image;
		GPU_Target* alias_target;
		GPU_Image* alias_image;
		Uint32 startTime;
		long frameCount;

		Uint8 done;
		SDL_Event event;

		image = GPU_LoadImage("data/test.bmp");
		if (image == NULL)
			return -1;

		alias_target = GPU_CreateAliasTarget(screen);

		GPU_SetViewport(screen, GPU_MakeRect(50, 30, 400, 300));

		GPU_SetViewport(alias_target, GPU_MakeRect(400, 30, 400, 300));
		GPU_SetTargetRGBA(alias_target, 255, 100, 100, 200);


		alias_image = GPU_CreateAliasImage(image);

		GPU_SetImageFilter(alias_image, GPU_FILTER_NEAREST);
		GPU_SetRGBA(alias_image, 100, 255, 100, 200);


		startTime = SDL_GetTicks();
		frameCount = 0;

		done = 0;
		while (!done)
		{
			while (SDL_PollEvent(&event))
			{
				if (event.type == SDL_QUIT)
					done = 1;
				else if (event.type == SDL_KEYDOWN)
				{
					if (event.key.keysym.sym == SDLK_ESCAPE)
						done = 1;
				}
			}

			GPU_Clear(screen);

			GPU_Blit(image, NULL, screen, image->w / 2, image->h / 2);
			GPU_Blit(alias_image, NULL, screen, image->w + alias_image->w / 2, alias_image->h / 2);

			GPU_Blit(image, NULL, alias_target, image->w / 2, image->h / 2);
			GPU_Blit(alias_image, NULL, alias_target, image->w + alias_image->w / 2, alias_image->h / 2);

			GPU_Flip(screen);

			frameCount++;
			if (frameCount % 500 == 0)
				printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime));
		}

		printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime));

		GPU_FreeImage(alias_image);
		GPU_FreeImage(image);
		GPU_FreeTarget(alias_target);
	}

	GPU_Quit();
	
	return 0;
}
Example #5
0
int main(int argc, char* argv[])
{
	GPU_Target* screen;

	printRenderers();
	
	screen = GPU_Init(1024, 700, GPU_DEFAULT_INIT_FLAGS);
	if(screen == NULL)
		return -1;
	
	printCurrentRenderer();
	
	{
		Uint32 startTime;
		long frameCount;
		Uint8 done;
		SDL_Event event;
		
        float x, y;
        SDL_Surface* font_surface;
        DemoFont* font;
        GPU_Rect rect1, rect2;
        
        GPU_Image* image = GPU_LoadImage("data/happy_52x63.bmp");
        if(image == NULL)
            return -1;
        
        
        font_surface = GPU_LoadSurface("data/comic14.png");
        font = FONT_Alloc(font_surface);
        GPU_SetRGB(font->image, 255, 0, 0);
        SDL_FreeSurface(font_surface);
        
        
        rect1 = GPU_MakeRect(0.0f, 0.0f, image->w*3, image->h*3);
        rect2 = GPU_MakeRect(-image->w*2, -image->h*2, image->w*3, image->h*3);
        
        startTime = SDL_GetTicks();
        frameCount = 0;
        
        
        done = 0;
        while(!done)
        {
            while(SDL_PollEvent(&event))
            {
                if(event.type == SDL_QUIT)
                    done = 1;
                else if(event.type == SDL_KEYDOWN)
                {
                    if(event.key.keysym.sym == SDLK_ESCAPE)
                        done = 1;
                }
            }
            
            GPU_Clear(screen);
            
            
            x = 0;
            y = 0;
            FONT_Draw(font, screen, x + 10, y + 10, "NONE");
            x += 40;
            y += 20;
            GPU_SetWrapMode(image, GPU_WRAP_NONE, GPU_WRAP_NONE);
            GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2);
            x += image->w*4;
            GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2);
            
            x = 0;
            y += (rect1.h + 10);
            FONT_Draw(font, screen, x + 10, y + 10, "REPEAT");
            x += 40;
            y += 20;
            GPU_SetWrapMode(image, GPU_WRAP_REPEAT, GPU_WRAP_REPEAT);
            GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2);
            x += image->w*4;
            GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2);
            
            x = 0;
            y += (rect1.h + 10);
            FONT_Draw(font, screen, x + 10, y + 10, "MIRRORED");
            x += 40;
            y += 20;
            GPU_SetWrapMode(image, GPU_WRAP_MIRRORED, GPU_WRAP_MIRRORED);
            GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2);
            x += image->w*4;
            GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2);
            
            x = 500;
            y = 0;
            FONT_Draw(font, screen, x + 10, y + 10, "REPEAT/MIRRORED");
            x += 40;
            y += 20;
            GPU_SetWrapMode(image, GPU_WRAP_REPEAT, GPU_WRAP_MIRRORED);
            GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2);
            x += image->w*4;
            GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2);
            
            x = 500;
            y += (rect1.h + 10);
            FONT_Draw(font, screen, x + 10, y + 10, "NONE/REPEAT");
            x += 40;
            y += 20;
            GPU_SetWrapMode(image, GPU_WRAP_NONE, GPU_WRAP_REPEAT);
            GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2);
            x += image->w*4;
            GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2);
            
            x = 500;
            y += (rect1.h + 10);
            FONT_Draw(font, screen, x + 10, y + 10, "NONE/MIRRORED");
            x += 40;
            y += 20;
            GPU_SetWrapMode(image, GPU_WRAP_NONE, GPU_WRAP_MIRRORED);
            GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2);
            x += image->w*4;
            GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2);
            
            GPU_Flip(screen);
            
            frameCount++;
            if(frameCount%500 == 0)
                printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime));
        }
        
        printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime));
        
        FONT_Free(font);
        GPU_FreeImage(image);
	}
	
	GPU_Quit();
	
	return 0;
}