Add window scaling, TODO: fix slowdown
This commit is contained in:
parent
5833de18f4
commit
4832492f1e
@ -29,7 +29,7 @@ public class Main {
|
|||||||
if (RestartJVM.restartJVM()) {
|
if (RestartJVM.restartJVM()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Render.init();
|
||||||
Screen.init();
|
Screen.init();
|
||||||
scenes.push(new Game());
|
scenes.push(new Game());
|
||||||
|
|
||||||
|
@ -29,17 +29,28 @@ import static org.libsdl.api.pixels.SDL_PixelFormatEnum.*;
|
|||||||
import static org.libsdl.api.video.SDL_WindowFlags.*;
|
import static org.libsdl.api.video.SDL_WindowFlags.*;
|
||||||
import static org.libsdl.api.video.SdlVideo.*;
|
import static org.libsdl.api.video.SdlVideo.*;
|
||||||
import static com.fmudanyali.Screen.*;
|
import static com.fmudanyali.Screen.*;
|
||||||
|
import static org.libsdl.api.hints.SdlHintsConst.*;
|
||||||
|
import static org.libsdl.api.hints.SdlHints.*;
|
||||||
|
import static org.libsdl.api.render.SdlRender.SDL_RenderSetLogicalSize;
|
||||||
|
|
||||||
public class Render {
|
public class Render {
|
||||||
public static SDL_Window window = SDL_CreateWindow("SDL Java Test",
|
public static SDL_Window window;
|
||||||
SDL_WINDOWPOS_CENTERED(), SDL_WINDOWPOS_CENTERED(),
|
public static SDL_Renderer renderer;
|
||||||
WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
|
|
||||||
|
|
||||||
public static SDL_Renderer renderer =
|
|
||||||
SDL_CreateRenderer(Render.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
|
||||||
|
|
||||||
public static int bgw, bgh;
|
public static int bgw, bgh;
|
||||||
|
|
||||||
|
public static void init(){
|
||||||
|
window = SDL_CreateWindow("DanmakuProject SDL",
|
||||||
|
SDL_WINDOWPOS_CENTERED(), SDL_WINDOWPOS_CENTERED(),
|
||||||
|
WIDTH, HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
|
||||||
|
|
||||||
|
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
||||||
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
||||||
|
|
||||||
|
renderer =
|
||||||
|
SDL_CreateRenderer(Render.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
|
|
||||||
|
SDL_RenderSetLogicalSize(renderer, Screen.WIDTH, Screen.HEIGHT);
|
||||||
|
}
|
||||||
public static SDL_Texture createBackgroundFromTexture(
|
public static SDL_Texture createBackgroundFromTexture(
|
||||||
SDL_Renderer renderer, SDL_Texture texture, int cols, int rows
|
SDL_Renderer renderer, SDL_Texture texture, int cols, int rows
|
||||||
){
|
){
|
||||||
@ -61,7 +72,7 @@ public class Render {
|
|||||||
bgh = txh * rows;
|
bgh = txh * rows;
|
||||||
// Create background texture
|
// Create background texture
|
||||||
SDL_Texture background = SDL_CreateTexture(
|
SDL_Texture background = SDL_CreateTexture(
|
||||||
renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, bgw, bgh);
|
renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, bgw, bgh);
|
||||||
// Set render target to background
|
// Set render target to background
|
||||||
SDL_SetRenderTarget(renderer, background);
|
SDL_SetRenderTarget(renderer, background);
|
||||||
// Create position rectangle for the texture
|
// Create position rectangle for the texture
|
||||||
|
@ -25,10 +25,12 @@ import static org.libsdl.api.event.SdlEvents.*;
|
|||||||
import static com.fmudanyali.Render.*;
|
import static com.fmudanyali.Render.*;
|
||||||
import static org.libsdl.api.keycode.SDL_Keycode.*;
|
import static org.libsdl.api.keycode.SDL_Keycode.*;
|
||||||
import static org.libsdl.api.render.SdlRender.*;
|
import static org.libsdl.api.render.SdlRender.*;
|
||||||
|
import static org.libsdl.api.error.SdlError.SDL_GetError;
|
||||||
|
|
||||||
public class Game extends Scene {
|
public class Game extends Scene {
|
||||||
public static boolean exit = false;
|
public static boolean exit = false;
|
||||||
public static boolean escPressed = false;
|
public static boolean escPressed = false;
|
||||||
|
public int kek = 0;
|
||||||
|
|
||||||
public Player player = new Player();
|
public Player player = new Player();
|
||||||
|
|
||||||
@ -65,6 +67,13 @@ public class Game extends Scene {
|
|||||||
|
|
||||||
player.movement();
|
player.movement();
|
||||||
Screen.scroll();
|
Screen.scroll();
|
||||||
|
/*
|
||||||
|
++kek;
|
||||||
|
if(kek == 60){
|
||||||
|
System.out.println(SDL_GetError());
|
||||||
|
kek = 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
SDL_RenderCopy(renderer, Screen.wallpaper, null, null);
|
SDL_RenderCopy(renderer, Screen.wallpaper, null, null);
|
||||||
|
Reference in New Issue
Block a user