예제 #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 i = 1;
	while(i > 0)
    {
        if(i == 1)
            i = do_interleaved(screen);
        else if(i == 2)
            i = do_separate(screen);
        else if(i == 3)
            i = do_attributes(screen);
        else
            i = 0;
    }
	
	GPU_Quit();
	
	return i;
}
예제 #2
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/test.bmp");
        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_Clear(screen);
            
            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;
}
예제 #3
0
파일: main.c 프로젝트: Helios-vmg/sdl-gpu
int main(int argc, char* argv[])
{
	GPU_Target* screen;
	
	// Prepare renderer for SDL_gpu to use
	GPU_RendererID rendererID = GPU_MakeRendererID("Dummy", GPU_ReserveNextRendererEnum(), 1, 0);
	GPU_RegisterRenderer(rendererID, &create_dummy_renderer, &free_dummy_renderer);

	printRenderers();
	
	// Request this specific renderer
	screen = GPU_InitRenderer(rendererID.renderer, 800, 600, GPU_DEFAULT_INIT_FLAGS);
	if(screen == NULL)
		return -1;
	
	printCurrentRenderer();
	
	{
		Uint8 done;
		SDL_Event event;
		
		GPU_Image* image = GPU_LoadImage("data/test.bmp");
		if(image == NULL)
            GPU_Log("Failed to load image.\n");
        
        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, screen->w/2, screen->h/2);
            
            GPU_Flip(screen);
            
            // Long delay to keep the logging from piling up too much
            SDL_Delay(500);
        }
        
        GPU_FreeImage(image);
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #4
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();
	
	Uint32 startTime = SDL_GetTicks();
	long frameCount = 0;
	
	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;
			}
		}
		
		GPU_Clear(screen);
		
		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_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;
		
        int shapeType;
        int numShapeTypes;
        int i;
        #define NUM_COLORS 20
        SDL_Color colors[NUM_COLORS];
        
        #define NUM_PIXELS NUM_COLORS
        int px[NUM_PIXELS];
        int py[NUM_PIXELS];
        
        #define NUM_LINES NUM_COLORS
        int lx1[NUM_LINES];
        int ly1[NUM_LINES];
        int lx2[NUM_LINES];
        int ly2[NUM_LINES];
        
        #define NUM_TRIS NUM_COLORS
        int tx1[NUM_TRIS];
        int ty1[NUM_TRIS];
        int tx2[NUM_TRIS];
        int ty2[NUM_TRIS];
        int tx3[NUM_TRIS];
        int ty3[NUM_TRIS];
        
        #define NUM_RECTS NUM_COLORS
        int rx1[NUM_RECTS];
        int ry1[NUM_RECTS];
        int rx2[NUM_RECTS];
        int ry2[NUM_RECTS];
        float rr[NUM_RECTS];
        
        #define NUM_ARCS NUM_COLORS
        int ax[NUM_ARCS];
        int ay[NUM_ARCS];
        float ar[NUM_ARCS];
        float ar2[NUM_ARCS];
        float aa1[NUM_ARCS];
        float aa2[NUM_ARCS];
        
        #define NUM_POLYS NUM_COLORS
        int pn[NUM_POLYS];
        float* pv[NUM_POLYS];
        
        Uint8 blend;
        float thickness;
        
        startTime = SDL_GetTicks();
        frameCount = 0;
        
        shapeType = 0;
        numShapeTypes = 18;
        
        for(i = 0; i < NUM_COLORS; i++)
        {
            colors[i].r = rand()%256;
            colors[i].g = rand()%256;
            colors[i].b = rand()%256;
            GET_ALPHA(colors[i]) = rand()%256;
        }
        
        
        
        for(i = 0; i < NUM_PIXELS; i++)
        {
            px[i] = rand()%screen->w;
            py[i] = rand()%screen->h;
        }
        
        for(i = 0; i < NUM_LINES; i++)
        {
            lx1[i] = rand()%screen->w;
            ly1[i] = rand()%screen->h;
            lx2[i] = rand()%screen->w;
            ly2[i] = rand()%screen->h;
        }
        
        for(i = 0; i < NUM_TRIS; i++)
        {
            tx1[i] = rand()%screen->w;
            ty1[i] = rand()%screen->h;
            tx2[i] = rand()%screen->w;
            ty2[i] = rand()%screen->h;
            tx3[i] = rand()%screen->w;
            ty3[i] = rand()%screen->h;
        }
        
        
        for(i = 0; i < NUM_RECTS; i++)
        {
            rx1[i] = rand()%screen->w;
            ry1[i] = rand()%screen->h;
            rx2[i] = rand()%screen->w;
            ry2[i] = rand()%screen->h;
            rr[i] = rand()%10 + 2;
        }
        
        for(i = 0; i < NUM_ARCS; i++)
        {
            ax[i] = rand()%screen->w;
            ay[i] = rand()%screen->h;
            ar[i] = (rand()%screen->h)/10.0f;
            ar2[i] = ((rand()%101)/100.0f)*ar[i];
            aa1[i] = rand()%360;
            aa2[i] = rand()%360;
        }
        
        for(i = 0; i < NUM_POLYS; i++)
        {
            float cx = rand()%screen->w;
            float cy = rand()%screen->h;
            float radius = 20 + rand()%(screen->w/8);
            
            int j;
            
            pn[i] = rand()%8 + 3;
            pv[i] = (float*)malloc(2*pn[i]*sizeof(float));
            
            for(j = 0; j < pn[i]*2; j+=2)
            {
                pv[i][j] = cx + radius*cos(2*M_PI*(((float)j)/(pn[i]*2))) + rand()%((int)radius/2);
                pv[i][j+1] = cy + radius*sin(2*M_PI*(((float)j)/(pn[i]*2))) + rand()%((int)radius/2);
            }
        }
        
        blend = 0;
        thickness = 1.0f;
        
        GPU_SetShapeBlending(blend);
        
        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)
                    {
                        shapeType++;
                        if(shapeType >= numShapeTypes)
                            shapeType = 0;
                    }
                    else if(event.key.keysym.sym == SDLK_BACKSPACE)
                    {
                        shapeType--;
                        if(shapeType < 0)
                            shapeType = numShapeTypes-1;
                    }
                    else if(event.key.keysym.sym == SDLK_b)
                    {
                        blend = !blend;
                        GPU_SetShapeBlending(blend);
                    }
                    else if(event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_EQUALS)
                    {
                        thickness += 0.25f;
                        GPU_LogError("thickness: %.2f\n", thickness);
                        GPU_SetLineThickness(thickness);
                    }
                    else if(event.key.keysym.sym == SDLK_DOWN || event.key.keysym.sym == SDLK_MINUS)
                    {
                        if(thickness > 0.25f)
                            thickness -= 0.25f;
                        GPU_LogError("thickness: %.2f\n", thickness);
                        GPU_SetLineThickness(thickness);
                    }
                }
                else if(event.type == SDL_MOUSEBUTTONDOWN)
                {
                    if(event.button.button == SDL_BUTTON_LEFT)
                    {
                        shapeType++;
                        if(shapeType >= numShapeTypes)
                            shapeType = 0;
                    }
                    else if(event.button.button == SDL_BUTTON_RIGHT)
                    {
                        shapeType--;
                        if(shapeType < 0)
                            shapeType = numShapeTypes-1;
                    }
                }
            }
            
            GPU_Clear(screen);
            
            switch(shapeType)
            {
                case 0:
                    for(i = 0; i < NUM_PIXELS; i++)
                    {
                        GPU_Pixel(screen, px[i], py[i], colors[i]);
                    }
                    break;
                case 1:
                    for(i = 0; i < NUM_LINES; i++)
                    {
                        GPU_Line(screen, lx1[i], ly1[i], lx2[i], ly2[i], colors[i]);
                    }
                    break;
                case 2:
                    for(i = 0; i < NUM_TRIS; i++)
                    {
                        GPU_Tri(screen, tx1[i], ty1[i], tx2[i], ty2[i], tx3[i], ty3[i], colors[i]);
                    }
                    break;
                case 3:
                    for(i = 0; i < NUM_TRIS; i++)
                    {
                        GPU_TriFilled(screen, tx1[i], ty1[i], tx2[i], ty2[i], tx3[i], ty3[i], colors[i]);
                    }
                    break;
                case 4:
                    for(i = 0; i < NUM_RECTS; i++)
                    {
                        GPU_Rectangle(screen, rx1[i], ry1[i], rx2[i], ry2[i], colors[i]);
                    }
                    break;
                case 5:
                    for(i = 0; i < NUM_RECTS; i++)
                    {
                        GPU_RectangleFilled(screen, rx1[i], ry1[i], rx2[i], ry2[i], colors[i]);
                    }
                    break;
                case 6:
                    for(i = 0; i < NUM_RECTS; i++)
                    {
                        GPU_RectangleRound(screen, rx1[i], ry1[i], rx2[i], ry2[i], rr[i], colors[i]);
                    }
                    break;
                case 7:
                    for(i = 0; i < NUM_RECTS; i++)
                    {
                        GPU_RectangleRoundFilled(screen, rx1[i], ry1[i], rx2[i], ry2[i], rr[i], colors[i]);
                    }
                    break;
                case 8:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_Arc(screen, ax[i], ay[i], ar[i], aa1[i], aa2[i], colors[i]);
                    }
                    break;
                case 9:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_ArcFilled(screen, ax[i], ay[i], ar[i], aa1[i], aa2[i], colors[i]);
                    }
                    break;
                case 10:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_Circle(screen, ax[i], ay[i], ar[i], colors[i]);
                    }
                    break;
                case 11:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_CircleFilled(screen, ax[i], ay[i], ar[i], colors[i]);
                    }
                    break;
                case 12:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_Ellipse(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], colors[i]);
                    }
                    break;
                case 13:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_EllipseFilled(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], colors[i]);
                    }
                    break;
                case 14:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_Sector(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], aa2[i], colors[i]);
                    }
                    break;
                case 15:
                    for(i = 0; i < NUM_ARCS; i++)
                    {
                        GPU_SectorFilled(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], aa2[i], colors[i]);
                    }
                    break;
                case 16:
                    for(i = 0; i < NUM_POLYS; i++)
                    {
                        GPU_Polygon(screen, pn[i], pv[i], colors[i]);
                    }
                    break;
                case 17:
                    for(i = 0; i < NUM_POLYS; i++)
                    {
                        GPU_PolygonFilled(screen, pn[i], pv[i], colors[i]);
                    }
                    break;
            }
            
            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));
        
        for(i = 0; i < NUM_POLYS; i++)
        {
            free(pv[i]);
        }
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #6
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;
}
예제 #7
0
파일: main.c 프로젝트: DataFighter/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;
        Uint32 v, f, p;
        GPU_ShaderBlock block;
        int uloc;
        int timeloc;
        float dt;
#define MAX_SPRITES 50
        int numSprites;
        float x[MAX_SPRITES];
        float y[MAX_SPRITES];
        float velx[MAX_SPRITES];
        float vely[MAX_SPRITES];
        int i;

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

        block = load_shaders(&v, &f, &p);
        uloc = GPU_GetUniformLocation(p, "tex");
        GPU_SetUniformi(uloc, 0);
        timeloc = GPU_GetUniformLocation(p, "time");

        dt = 0.010f;

        startTime = SDL_GetTicks();
        frameCount = 0;

        numSprites = 1;

        for(i = 0; i < MAX_SPRITES; i++)
        {
            x[i] = rand()%screen->w;
            y[i] = rand()%screen->h;
            velx[i] = 10 + rand()%screen->w/10;
            vely[i] = 10 + rand()%screen->h/10;
        }


        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_EQUALS || event.key.keysym.sym == SDLK_PLUS)
                    {
                        if(numSprites < MAX_SPRITES)
                            numSprites++;
                    }
                    else if(event.key.keysym.sym == SDLK_MINUS)
                    {
                        if(numSprites > 0)
                            numSprites--;
                    }
                    else if(event.key.keysym.sym == SDLK_SPACE)
                    {
                        if(GPU_IsDefaultShaderProgram(GPU_GetCurrentShaderProgram()))
                        {
                            GPU_ActivateShaderProgram(p, &block);
                            uloc = GPU_GetUniformLocation(p, "tex");
                            GPU_SetUniformi(uloc, 0);
                            timeloc = GPU_GetUniformLocation(p, "time");
                        }
                        else
                            GPU_ActivateShaderProgram(0, NULL);
                    }
                }
            }

            for(i = 0; i < numSprites; i++)
            {
                x[i] += velx[i]*dt;
                y[i] += vely[i]*dt;
                if(x[i] < 0)
                {
                    x[i] = 0;
                    velx[i] = -velx[i];
                }
                else if(x[i]> screen->w)
                {
                    x[i] = screen->w;
                    velx[i] = -velx[i];
                }

                if(y[i] < 0)
                {
                    y[i] = 0;
                    vely[i] = -vely[i];
                }
                else if(y[i]> screen->h)
                {
                    y[i] = screen->h;
                    vely[i] = -vely[i];
                }
            }

            GPU_SetUniformf(timeloc, SDL_GetTicks()/1000.0f);

            GPU_Clear(screen);

            for(i = 0; i < numSprites; i++)
            {
                GPU_Blit(image, NULL, screen, x[i], y[i]);
            }

            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);

        free_shaders(v, f, p);
    }

    GPU_Quit();

    return 0;
}
예제 #8
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;
}
예제 #9
0
파일: main.c 프로젝트: shadowmint/sdl-gpu
int main(int argc, char* argv[])
{
	printRenderers();
	
	GPU_Target* screen = GPU_Init(1024, 700, GPU_DEFAULT_INIT_FLAGS);
	if(screen == NULL)
		return -1;
	
	printCurrentRenderer();
	
	GPU_Image* image = GPU_LoadImage("data/small_test.bmp");
	if(image == NULL)
		return -1;
    
    
	SDL_Surface* font_surface = GPU_LoadSurface("data/comic14.png");
	DemoFont* font = FONT_Alloc(font_surface);
	GPU_SetRGB(font->image, 255, 0, 0);
	SDL_FreeSurface(font_surface);
	
    
    GPU_Rect rect1 = {0.0f, 0.0f, image->w*3, image->h*3};
    GPU_Rect rect2 = {-image->w*2, -image->h*2, image->w*3, image->h*3};
	
	Uint32 startTime = SDL_GetTicks();
	long frameCount = 0;
	
	
	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;
			}
		}
		
		GPU_Clear(screen);
		
		
		float x = 0;
		float 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;
}
예제 #10
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();

	{
		GPU_Image* image;
		float x, y;
		float velx, vely;
		float dt;
		Uint32 startTime;
		long frameCount;
		Uint8 done;
		SDL_Event event;

		image = GPU_LoadImage("data/test3.png");
		if (image == NULL)
			return -1;

		x = 0;
		y = 0;
		velx = 50.0f;
		vely = 70.0f;

		dt = 0.010f;

		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;
				}
			}

			x += velx*dt;
			y += vely*dt;
			if (x < 0)
			{
				x = 0;
				velx = -velx;
			}
			else if (x + image->w > screen->w)
			{
				x = screen->w - image->w;
				velx = -velx;
			}

			if (y < 0)
			{
				y = 0;
				vely = -vely;
			}
			else if (y + image->h > screen->h)
			{
				y = screen->h - image->h;
				vely = -vely;
			}

			GPU_Clear(screen);

			GPU_Blit(image, NULL, screen, 50, 50);
			GPU_Blit(image, NULL, screen, 150, 50);
			GPU_Blit(image, NULL, screen, 350, 250);

			GPU_SetBlending(image, 1);
			GPU_SetRGBA(image, 255, 100, 255, 127.5f + 127.5f*sin(SDL_GetTicks() / 1000.0f));

			GPU_Blit(image, NULL, screen, x, y);

			GPU_SetRGBA(image, 255, 255, 255, 255);
			GPU_SetBlending(image, 0);

			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;
}
예제 #11
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;
        #define MAX_SPRITES 100
        int numSprites;
        float positions[2*MAX_SPRITES];
        float colors[4*4*MAX_SPRITES];
        float expanded_colors[4*MAX_SPRITES];
        float src_rects[4*MAX_SPRITES];
        Uint32 v, f, p;
        GPU_ShaderBlock block;
        Uint8 shader_index;
        int i;
        SDL_Color color = {255, 255, 255, 255};
        SDL_Color red = {255, 0, 0, 255};
        SDL_Color green = {0, 255, 0, 255};
        SDL_Color blue = {0, 0, 255, 255};
        GPU_Rect src_rect;
        
        int mx, my;
        Uint32 mouse_state;
        
        image = GPU_LoadImage("data/happy_50x50.bmp");
        if(image == NULL)
            return -1;
        
        numSprites = 0;
        
        color_attr.format = GPU_MakeAttributeFormat(4, GPU_TYPE_FLOAT, 0, 4*sizeof(float), 0);
        color_attr.format.is_per_sprite = 0;
        color_attr.values = colors;
        
        
        block = load_shaders(&v, &f, &p);
        
        shader_index = 1;
        set_shader(p, &block);
        
        startTime = SDL_GetTicks();
        frameCount = 0;
        
        src_rect.x = 0;
        src_rect.y = 0;
        src_rect.w = image->w;
        src_rect.h = image->h;
        
        add_sprite(positions, colors, expanded_colors, src_rects, &numSprites, color, src_rect);
        
        done = 0;
        while(!done)
        {
            while(SDL_PollEvent(&event))
            {
                if(event.type == SDL_QUIT)
                    done = 1;
                else if(event.type == SDL_MOUSEBUTTONDOWN)
                {
                    if(event.button.x <= 150 && event.button.y <= 150)
                    {
                        if(event.button.button == SDL_BUTTON_LEFT)
                        {
                            float dx = event.button.x/3 - src_rect.x;
                            float dy = event.button.y/3 - src_rect.y;
                            src_rect.x = event.button.x/3;
                            src_rect.y = event.button.y/3;
                            src_rect.w -= dx;
                            src_rect.h -= dy;
                        }
                        else if(event.button.button == SDL_BUTTON_RIGHT)
                        {
                            src_rect.w = event.button.x/3 - src_rect.x;
                            src_rect.h = event.button.y/3 - src_rect.y;
                        }
                    }
                }
                else if(event.type == SDL_KEYDOWN)
                {
                    if(event.key.keysym.sym == SDLK_ESCAPE)
                        done = 1;
                    else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS)
                    {
                        if(numSprites < MAX_SPRITES)
                            add_sprite(positions, colors, expanded_colors, src_rects, &numSprites, color, src_rect);
                    }
                    else if(event.key.keysym.sym == SDLK_MINUS)
                    {
                        if(numSprites > 0)
                            numSprites--;
                    }
                    else if(event.key.keysym.sym == SDLK_SPACE)
                    {
                        shader_index++;
                        shader_index %= 2;
                        if(shader_index == 0)
                            set_shader(0, NULL);
                        else if(shader_index == 1)
                            set_shader(p, &block);
                    }
                    else if(event.key.keysym.sym == SDLK_RETURN)
                    {
                        use_color_expansion = !use_color_expansion;
                        if(use_color_expansion)
                        {
                            GPU_LogError("Using attribute expansion.\n");
                            color_attr.format.is_per_sprite = 1;
                            color_attr.values = expanded_colors;
                        }
                        else
                        {
                            GPU_LogError("Using per-vertex attributes.\n");
                            color_attr.format.is_per_sprite = 0;
                            color_attr.values = colors;
                        }
                    }
                }
            }
            
            mouse_state = SDL_GetMouseState(&mx, &my);
            if(mouse_state & (SDL_BUTTON_LMASK | SDL_BUTTON_RMASK))
            {
                if(mx <= 150 && my <= 150)
                {
                    if(mouse_state & SDL_BUTTON_LMASK)
                    {
                        float dx = mx/3 - src_rect.x;
                        float dy = my/3 - src_rect.y;
                        src_rect.x = mx/3;
                        src_rect.y = my/3;
                        src_rect.w -= dx;
                        src_rect.h -= dy;
                    }
                    else if(mouse_state & SDL_BUTTON_RMASK)
                    {
                        src_rect.w = mx/3 - src_rect.x;
                        src_rect.h = my/3 - src_rect.y;
                    }
                }
            }
            
            GPU_SetUniformf(timeloc, SDL_GetTicks()/1000.0f);
            
            GPU_Clear(screen);
            
            if(use_color_expansion)
                GPU_SetAttributeSource(numSprites, color_attr);
            else
                GPU_SetAttributeSource(4*numSprites, color_attr);
            
            for(i = 0; i < numSprites; i++)
            {
                GPU_Rect r = {src_rects[4*i], src_rects[4*i+1], src_rects[4*i+2], src_rects[4*i+3]};
                GPU_Blit(image, &r, screen, positions[2*i], positions[2*i+1]);
            }
            //GPU_BlitBatchSeparate(image, screen, numSprites, positions, src_rects, expanded_colors, 0);
            
            set_shader(0, NULL);
            
            GPU_BlitScale(image, NULL, screen, 75, 75, 3.0f, 3.0f);
            GPU_Rectangle(screen, 3*src_rect.x, 3*src_rect.y, 3*(src_rect.x + src_rect.w), 3*(src_rect.y + src_rect.h), red);
            GPU_CircleFilled(screen, 3*src_rect.x, 3*src_rect.y, 4, blue);
            GPU_CircleFilled(screen, 3*(src_rect.x + src_rect.w), 3*(src_rect.y + src_rect.h), 4, green);
            
            if(shader_index == 1)
                set_shader(p, &block);
            
            
            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);
        
        free_shaders(v, f, p);
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #12
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;
}
예제 #13
0
파일: main.c 프로젝트: 07151129/sdl-gpu
int main(int argc, char* argv[])
{
	GPU_Target* screen;

	printRenderers();
	GPU_SetPreInitFlags(GPU_INIT_DISABLE_VSYNC);
	screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS);
	if(screen == NULL)
		return -1;
	
	printCurrentRenderer();
	
	{
		Uint32 startTime;
		long frameCount;
		Uint8 done;
		SDL_Event event;
		
        float dt = 0.010f;
        
        int maxSprites = 50000;
        int numSprites = 101;
        
        float* x = (float*)malloc(sizeof(float)*maxSprites);
        float* y = (float*)malloc(sizeof(float)*maxSprites);
        float* velx = (float*)malloc(sizeof(float)*maxSprites);
        float* vely = (float*)malloc(sizeof(float)*maxSprites);
        int i;
        
        GPU_Image* image = GPU_LoadImage("data/small_test.png");
        if(image == NULL)
            return -1;
        
        GPU_SetSnapMode(image, GPU_SNAP_NONE);
        
        startTime = SDL_GetTicks();
        frameCount = 0;
        for(i = 0; i < maxSprites; i++)
        {
            x[i] = rand()%screen->w;
            y[i] = rand()%screen->h;
            velx[i] = 10 + rand()%screen->w/10;
            vely[i] = 10 + rand()%screen->h/10;
            if(rand()%2)
                velx[i] = -velx[i];
            if(rand()%2)
                vely[i] = -vely[i];
        }
        
        
        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_EQUALS || event.key.keysym.sym == SDLK_PLUS)
                    {
                        if(numSprites < maxSprites)
                            numSprites += 100;
                        GPU_LogError("Sprites: %d\n", numSprites);
                        frameCount = 0;
                        startTime = SDL_GetTicks();
                    }
                    else if(event.key.keysym.sym == SDLK_MINUS)
                    {
                        if(numSprites > 1)
                            numSprites -= 100;
                        if(numSprites < 1)
                            numSprites = 1;
                        GPU_LogError("Sprites: %d\n", numSprites);
                        frameCount = 0;
                        startTime = SDL_GetTicks();
                    }
                }
            }
            
            for(i = 0; i < numSprites; i++)
            {
                x[i] += velx[i]*dt;
                y[i] += vely[i]*dt;
                if(x[i] < 0)
                {
                    x[i] = 0;
                    velx[i] = -velx[i];
                }
                else if(x[i]> screen->w)
                {
                    x[i] = screen->w;
                    velx[i] = -velx[i];
                }
                
                if(y[i] < 0)
                {
                    y[i] = 0;
                    vely[i] = -vely[i];
                }
                else if(y[i]> screen->h)
                {
                    y[i] = screen->h;
                    vely[i] = -vely[i];
                }
            }
            
            GPU_Clear(screen);
            
            for(i = 0; i < numSprites; i++)
            {
                GPU_Blit(image, NULL, screen, x[i], y[i]);
            }
            
            GPU_Flip(screen);
            
            frameCount++;
            if(SDL_GetTicks() - startTime > 5000)
            {
                printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime));
                frameCount = 0;
                startTime = SDL_GetTicks();
            }
        }
        
        printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime));
        
        free(x);
        free(y);
        free(velx);
        free(vely);
        
        GPU_FreeImage(image);
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #14
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)
    {
        GPU_LogError("Failed to init SDL_gpu.\n");
		return -1;
    }
	
	printCurrentRenderer();
	
	{
		Uint32 startTime;
		long frameCount;
		Uint8 done;
		SDL_Event event;
		
		GPU_Image* image;
		GPU_Image* image1;
        
        GPU_LogError("Loading image\n");
        image = GPU_LoadImage(IMAGE_FILE);
        if(image == NULL)
        {
            GPU_LogError("Failed to load image.\n");
            return -1;
        }
        
        GPU_LogError("Saving image\n");
        GPU_SaveImage(image, SAVE_FILE, GPU_FILE_AUTO);
        
        GPU_LogError("Reloading image\n");
        image1 = GPU_LoadImage(SAVE_FILE);
        if(image1 == NULL)
        {
            GPU_LogError("Failed to reload image.\n");
            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_Clear(screen);
            
            GPU_Blit(image, NULL, screen, screen->w/4, screen->h/2);
            GPU_Blit(image1, NULL, screen, 3*screen->w/4, screen->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(image);
        GPU_FreeImage(image1);
	}
	
	GPU_Quit();
	
	return 0;
}
예제 #15
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();

	{
		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;
}
예제 #16
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;
}
예제 #17
0
파일: main.c 프로젝트: DataFighter/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;

        int i = 0;

        float dt = 0.010f;

#define MAX_GROUPS 30
        Group groups[MAX_GROUPS];
        int num_groups;

        memset(groups, 0, sizeof(Group)*MAX_GROUPS);

        num_groups = 0;
        groups[num_groups] = create_first_group();
        num_groups++;

        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;
                    else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS)
                    {
                        for(i = 0; i < MAX_GROUPS; i++)
                        {
                            if(groups[i].target == NULL)
                            {
                                groups[i] = create_group();
                                num_groups++;
                                GPU_Log("Added window %u.  num_groups: %d\n", groups[i].target->context->windowID, num_groups);
                                break;
                            }
                        }
                    }
                    else if(event.key.keysym.sym == SDLK_MINUS)
                    {
                        if(num_groups > 0)
                        {

                            for(i = MAX_GROUPS-1; i >= 0; i--)
                            {
                                if(groups[i].target != NULL)
                                {
                                    GPU_Log("Removed window %u.  num_groups: %d\n", groups[i].target->context->windowID, num_groups-1);

                                    destroy_group(groups, i);

                                    num_groups--;
                                    break;
                                }
                            }

                            if(num_groups == 0)
                                done = 1;
                        }
                    }
                }
                else if(event.type == SDL_MOUSEBUTTONDOWN)
                {
                    GPU_Target* target = GPU_GetWindowTarget(event.button.windowID);
                    if(target == NULL)
                        GPU_Log("Clicked on window %u.  NULL target.\n", event.button.windowID);
                    else
                        GPU_Log("Clicked on window %u.  Target dims: %dx%d\n", event.button.windowID, target->w, target->h);
                }
                else if(event.type == SDL_WINDOWEVENT)
                {
                    if(event.window.event == SDL_WINDOWEVENT_CLOSE)
                    {
                        Uint8 closed = 0;
                        for(i = 0; i < MAX_GROUPS; i++)
                        {
                            if(groups[i].target != NULL && groups[i].target->context->windowID == event.window.windowID)
                            {
                                closed = 1;
                                GPU_Log("Removed window %u.  num_groups: %d\n", groups[i].target->context->windowID, num_groups-1);

                                destroy_group(groups, i);
                                num_groups--;
                                break;
                            }
                        }

                        // The last window was closed, then.
                        if(!closed || num_groups == 0)
                            done = 1;
                    }
                }
            }

            for(i = 0; i < MAX_GROUPS; i++)
            {
                if(groups[i].target == NULL)
                    continue;

                groups[i].sprite.x += groups[i].sprite.velx*dt;
                groups[i].sprite.y += groups[i].sprite.vely*dt;
                if(groups[i].sprite.x < 0)
                {
                    groups[i].sprite.x = 0;
                    groups[i].sprite.velx = -groups[i].sprite.velx;
                }
                else if(groups[i].sprite.x > screen_w)
                {
                    groups[i].sprite.x = screen_w;
                    groups[i].sprite.velx = -groups[i].sprite.velx;
                }

                if(groups[i].sprite.y < 0)
                {
                    groups[i].sprite.y = 0;
                    groups[i].sprite.vely = -groups[i].sprite.vely;
                }
                else if(groups[i].sprite.y > screen_h)
                {
                    groups[i].sprite.y = screen_h;
                    groups[i].sprite.vely = -groups[i].sprite.vely;
                }
            }

            for(i = 0; i < MAX_GROUPS; i++)
            {
                if(groups[i].target == NULL)
                    continue;

                GPU_Clear(groups[i].target);

                GPU_Blit(groups[i].sprite.image, NULL, groups[i].target, groups[i].sprite.x, groups[i].sprite.y);

                GPU_Flip(groups[i].target);
            }

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

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

        for(i = 0; i < MAX_GROUPS; i++)
        {
            if(groups[i].target == NULL)
                continue;

            destroy_group(groups, i);
        }

    }

    GPU_Quit();

    return 0;
}
예제 #18
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_Image* image1;
        GPU_Image* image1a;
        SDL_Color yellow = {246, 255, 0};
        SDL_Color red = {200, 0, 0};
        GPU_Image* image2;
        GPU_Image* image3;
        GPU_Image* image4;
        
        image = GPU_LoadImage("data/test3.png");
        if(image == NULL)
            return -1;
        
        image1 = GPU_CopyImage(image);
        
        makeColorTransparent(image1, yellow);
        
        image1a = GPU_CopyImage(image);
        
        replaceColor(image1a, yellow, red);
        
        
        
        
        image2 = GPU_CopyImage(image);
        
        shiftHSV(image2, 100, 0, 0);
        
        image3 = GPU_CopyImage(image);
        
        shiftHSV(image3, 0, -100, 0);
        
        image4 = GPU_CopyImage(image);
        
        shiftHSV(image4, 0, 0, 100);
        
        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, 150, 150);
            GPU_Blit(image1, NULL, screen, 300, 150);
            GPU_Blit(image1a, NULL, screen, 450, 150);
            GPU_Blit(image2, NULL, screen, 150, 300);
            GPU_Blit(image3, NULL, screen, 300, 300);
            GPU_Blit(image4, NULL, screen, 450, 300);
            
            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_FreeImage(image1);
        GPU_FreeImage(image1a);
        GPU_FreeImage(image2);
        GPU_FreeImage(image3);
        GPU_FreeImage(image4);
	}
	
	GPU_Quit();
	
	return 0;
}