#include "SDL.h"
#include "SDL_image.h"
#include <iostream>
int main(int argc, char* args[])
{
SDL_Init(SDL_INIT_VIDEO);
IMG_Init(IMG_INIT_PNG);
SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
SDL_CreateWindowAndRenderer(1024, 768, 0, &window, &renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_Surface* surface = IMG_Load("background.png");
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
int dt = 0;
int frames = 0;
bool running = true;
uint32_t ticks = SDL_GetTicks();
SDL_Event event;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
}
}
++frames;
dt = SDL_GetTicks() - ticks;
if (dt >= 1000) {
std::cout << frames / (dt / 1000.0) << '\n';
ticks += dt;
frames = 0;
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(texture);
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
return 0;
}
require 'gosu'
class Window < Gosu::Window
def initialize(*args)
super
@background = Gosu::Image.new('background.png')
@frames = 0
@ticks = Gosu.milliseconds
end
def update
@frames += 1
dt = Gosu.milliseconds - @ticks
return unless dt >= 1000
puts @frames / (dt / 1000.0)
@ticks += dt
@frames = 0
end
def draw
@background.draw(0, 0, 0)
end
def button_down(id)
case id
when Gosu::KbEscape
close
end
end
end
window = Window.new(1024, 768)
window.show
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl")
, I get an 'opengl' renderer with SDL_RENDERER_ACCELERATED and SDL_RENDERER_TARGETTEXTURE set. This results in about 275 FPS.render
-to-texture) :)
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill