예제 #1
0
파일: main.c 프로젝트: shadowmint/sdl-gpu
int main(int argc, char* argv[])
{
	printRenderers();
	
	GPU_Target* screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS);
	if(screen == NULL)
		return -1;
	
	printCurrentRenderer();
	
	int numImages = 0;
	
	GPU_Image* images[argc-1];
	int i;
	for(i = 1; i < argc; i++)
	{
		images[numImages] = GPU_LoadImage(argv[i]);
		if(images[numImages] != NULL)
			numImages++;
	}
	
	Uint8* keystates = SDL_GetKeyState(NULL);
	GPU_Camera camera = GPU_GetDefaultCamera();
	
	float dt = 0.010f;
	Uint8 done = 0;
	SDL_Event event;
	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;
			}
		}
		
		if(keystates[KEY_UP])
		{
			camera.y -= 200*dt;
		}
		else if(keystates[KEY_DOWN])
		{
			camera.y += 200*dt;
		}
		if(keystates[KEY_LEFT])
		{
			camera.x -= 200*dt;
		}
		else if(keystates[KEY_RIGHT])
		{
			camera.x += 200*dt;
		}
		if(keystates[KEY_MINUS])
		{
			camera.zoom -= 1.0f*dt;
		}
		else if(keystates[KEY_EQUALS])
		{
			camera.zoom += 1.0f*dt;
		}
		
		GPU_ClearRGBA(screen, 255, 255, 255, 255);
		
		GPU_SetCamera(screen, &camera);
		
		float x = 100;
		float y = 100;
		for(i = 0; i < numImages; i++)
		{
			float x_scale = 150.0f/images[i]->w;
			float y_scale = 150.0f/images[i]->h;
			GPU_BlitScale(images[i], NULL, screen, x, y, x_scale, y_scale);
			
			x += 200;
			
			if((i+1)%4 == 0)
			{
				x = 100;
				y += 200;
			}
		}
		
		
		GPU_Flip(screen);
		SDL_Delay(10);
	}
	
	for(i = 0; i < numImages; i++)
	{
		GPU_FreeImage(images[i]);
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #2
0
파일: main.c 프로젝트: ReemHA/unknottheplot
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();
	
	{
		Uint32 startTime;
		long frameCount;
		Uint8 done;
		SDL_Event event;
		int mx, my;
		GPU_Image* image;
		GPU_Target* target;
		SDL_Color c;
		
        image = GPU_LoadImage("data/test.bmp");
        if(image == NULL)
            return -1;
        
        target = GPU_LoadTarget(image);
        
        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;
                }
            }
            
            SDL_GetMouseState(&mx, &my);
            c = GPU_GetPixel(target, mx - 50, my - 50);
            
            GPU_ClearRGBA(screen, c.r, c.g, c.b, GET_ALPHA(c));
            
            GPU_Blit(image, NULL, screen, image->w/2 + 50, image->h/2 + 50);
            
            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(image);
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #3
0
파일: main.c 프로젝트: 07151129/sdl-gpu
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();

	{
		int numImages;
		GPU_Image** images;
		int i;
		const Uint8* keystates;
		GPU_Camera camera;
		float dt;
		Uint8 done;
		SDL_Event event;
		float x, y;

		images = (GPU_Image**)malloc(sizeof(GPU_Image*)*(argc - 1));

		numImages = 0;

		for (i = 1; i < argc; i++)
		{
			images[numImages] = GPU_LoadImage(argv[i]);
			if (images[numImages] != NULL)
				numImages++;
		}

		keystates = SDL_GetKeyState(NULL);
		camera = GPU_GetDefaultCamera();

		dt = 0.010f;
		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;
					else if (event.key.keysym.sym == SDLK_r)
					{
						camera.x = 0.0f;
						camera.y = 0.0f;
						camera.z = -10.0f;
						camera.zoom = 1.0f;
						camera.angle = 0.0f;
					}
				}
				else if (event.type == SDL_MOUSEBUTTONDOWN)
				{
					float x, y;
					GPU_GetVirtualCoords(screen, &x, &y, event.button.x, event.button.y);

					printScreenToWorld(x, y);
				}
			}

			if (keystates[KEY_UP])
			{
				camera.y -= 200 * dt;
			}
			else if (keystates[KEY_DOWN])
			{
				camera.y += 200 * dt;
			}
			if (keystates[KEY_LEFT])
			{
				camera.x -= 200 * dt;
			}
			else if (keystates[KEY_RIGHT])
			{
				camera.x += 200 * dt;
			}
			if (keystates[KEY_MINUS])
			{
				camera.zoom -= 1.0f*dt;
			}
			else if (keystates[KEY_EQUALS])
			{
				camera.zoom += 1.0f*dt;
			}

			GPU_ClearRGBA(screen, 255, 255, 255, 255);

			GPU_SetCamera(screen, &camera);

			x = 0;
			y = 0;
			for (i = 0; i < numImages; i++)
			{
				x += images[i]->w / 2.0f;
				y += images[i]->h / 2.0f;
				GPU_Blit(images[i], NULL, screen, x, y);
				x += images[i]->w / 2.0f;
				y += images[i]->h / 2.0f;
			}


			GPU_Flip(screen);
			SDL_Delay(10);
		}

		for (i = 0; i < numImages; i++)
		{
			GPU_FreeImage(images[i]);
		}

		free(images);
	}

	GPU_Quit();

	return 0;
}
예제 #4
0
파일: main.c 프로젝트: 07151129/sdl-gpu
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();
	
	{
		Uint32 startTime;
		long frameCount;
		Uint8 done;
		SDL_Event event;
        
        GPU_Image* image = GPU_LoadImage("data/npot1.png");
        if(image == NULL)
            return -1;
        
        
        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_ClearRGBA(screen, 200, 200, 255, 255);
            
            GPU_Blit(image, NULL, screen, image->w/2, image->h/2);
            GPU_BlitTransform(image, NULL, screen, screen->w/2, screen->h/2, 360*sin(SDL_GetTicks()/2000.0f), 2.5*sin(SDL_GetTicks()/1000.0f), 2.5*sin(SDL_GetTicks()/1200.0f));
            
            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(image);
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #5
0
파일: main.c 프로젝트: 07151129/sdl-gpu
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();
	
	{
		Uint32 startTime;
		long frameCount;
		Uint8 done;
		SDL_Event event;
		const Uint8* keystates;
        GPU_Camera camera;
		float dt;
		SDL_Surface* surface;
		GPU_Image* image;
		GPU_Image* image1;
		GPU_Image* image2;
		GPU_Image* image3;
		GPU_Image* image4;
		
        image = GPU_LoadImage("data/test.bmp");
        //image = GPU_LoadImage("data/big_test.png");
        if(image == NULL)
            return -1;

        // Copying the annoying way
        image1 = GPU_CreateImage(image->w, image->h, GPU_FORMAT_RGBA);
        GPU_LoadTarget(image1);
        GPU_Blit(image, NULL, image1->target, image1->target->w/2, image1->target->h/2);
        GPU_FreeTarget(image1->target);

        // Copying the normal way
        image2 = GPU_CopyImage(image);

        // Copying from a surface dump
        surface = GPU_CopySurfaceFromImage(image);
        //GPU_SaveSurface(surface, "save_surf1.bmp", GPU_FILE_AUTO);
        image3 = GPU_CopyImageFromSurface(surface);
        SDL_FreeSurface(surface);

        // A buffer for window capture
        image4 = NULL;


        keystates = SDL_GetKeyState(NULL);
        camera = GPU_GetDefaultCamera();

        startTime = SDL_GetTicks();
        frameCount = 0;

        dt = 0.010f;
        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;
                    else if(event.key.keysym.sym == SDLK_SPACE)
                    {
                        // Take a window capture
                        GPU_FreeImage(image4);
                        image4 = GPU_CopyImageFromTarget(screen);
                    }
                }
            }
            
            if(keystates[KEY_UP])
            {
                camera.y -= 200*dt;
            }
            else if(keystates[KEY_DOWN])
            {
                camera.y += 200*dt;
            }
            if(keystates[KEY_LEFT])
            {
                camera.x -= 200*dt;
            }
            else if(keystates[KEY_RIGHT])
            {
                camera.x += 200*dt;
            }
            if(keystates[KEY_MINUS])
            {
                camera.zoom -= 1.0f*dt;
            }
            else if(keystates[KEY_EQUALS])
            {
                camera.zoom += 1.0f*dt;
            }
            
            
            GPU_ClearRGBA(screen, 100, 100, 100, 255);
            
            GPU_SetCamera(screen, &camera);
            
            GPU_Blit(image, NULL, screen, 128, 128);
            GPU_Blit(image1, NULL, screen, 128 + 256, 128);
            GPU_Blit(image2, NULL, screen, 128 + 512, 128);
            GPU_Blit(image3, NULL, screen, 128, 128 + 256);
            
            if(image4 != NULL)
                GPU_BlitScale(image4, NULL, screen, 3*screen->w/4, 3*screen->h/4, 0.25f, 0.25f);
            
            GPU_Flip(screen);
            
            frameCount++;
            if(frameCount%500 == 0)
                GPU_LogError("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime));
        }

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

        GPU_FreeImage(image);
        GPU_FreeImage(image1);
        GPU_FreeImage(image2);
        GPU_FreeImage(image3);
        GPU_FreeImage(image4);
	}
	
	GPU_Quit();
	
	return 0;
}