VERSIÓ 1.2.5
- [NEW] Soport bàsic per a shaders.
This commit is contained in:
25
mini.cpp
25
mini.cpp
@@ -5,6 +5,7 @@
|
||||
#include "gif.h"
|
||||
#include "gifenc.h"
|
||||
#include "jail_audio.h"
|
||||
#include "jshader.h"
|
||||
|
||||
#define MAX_TEXTURES 100
|
||||
|
||||
@@ -78,6 +79,7 @@ bool should_quit = false;
|
||||
SDL_Window *mini_win;
|
||||
SDL_Renderer *mini_ren;
|
||||
SDL_Texture *mini_bak;
|
||||
SDL_Texture *mini_shadertex;
|
||||
Uint32 windowID;
|
||||
Uint32 *pixels;
|
||||
int pitch;
|
||||
@@ -300,8 +302,9 @@ void createDisplay() {
|
||||
if (screen_zoom <= 0) screen_zoom = 1;
|
||||
while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--;
|
||||
|
||||
mini_win = SDL_CreateWindow(window_title, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN:SDL_WINDOW_RESIZABLE);
|
||||
mini_win = SDL_CreateWindow(window_title, screen_width*screen_zoom, screen_height*screen_zoom, SDL_WINDOW_OPENGL|(screen_fullscreen?SDL_WINDOW_FULLSCREEN:SDL_WINDOW_RESIZABLE));
|
||||
windowID = SDL_GetWindowID(mini_win);
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
||||
mini_ren = SDL_CreateRenderer(mini_win, NULL);
|
||||
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
||||
//SDL_SetRenderLogicalPresentation(mini_ren, screen_width, screen_height);
|
||||
@@ -314,6 +317,12 @@ void createDisplay() {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Pixelformat incorrecte: %i\n", real_pixelformat);
|
||||
exit(1);
|
||||
}
|
||||
mini_shadertex = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, screen_width*screen_zoom, screen_height*screen_zoom);
|
||||
SDL_SetTextureScaleMode(mini_shadertex, SDL_SCALEMODE_NEAREST);
|
||||
|
||||
int filesize;
|
||||
char *shaderfile = file_getfilebuffer("basic.glsl", filesize);
|
||||
shader::init(mini_win, mini_shadertex, shaderfile);
|
||||
//SDL_GetWindowPosition(mini_win, &windowpos_x, &windowpos_y);
|
||||
}
|
||||
|
||||
@@ -500,13 +509,18 @@ int main(int argc,char*argv[]){
|
||||
mouse_just_pressed = 0;
|
||||
pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID;
|
||||
}
|
||||
SDL_SetRenderTarget(mini_ren, mini_shadertex);
|
||||
SDL_SetRenderDrawColor(mini_ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(mini_ren);
|
||||
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
|
||||
for (uint32_t i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
|
||||
SDL_UnlockTexture(mini_bak);
|
||||
SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL);
|
||||
SDL_RenderPresent(mini_ren);
|
||||
SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL); //NEW
|
||||
|
||||
shader::render();
|
||||
//SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL);
|
||||
//SDL_RenderPresent(mini_ren);
|
||||
|
||||
fps_counter++;
|
||||
if (SDL_GetTicks()>=(fps_timer+1000)) {
|
||||
fps = fps_counter;
|
||||
@@ -579,11 +593,12 @@ uint32_t *loadpal(const char* filename, uint16_t *palsize) {
|
||||
}
|
||||
|
||||
void setpal(uint32_t *pal) {
|
||||
memcpy(palette, pal, 1024);
|
||||
for (int i=0; i<256; ++i) palette[i] = pal[i] | 0xff000000;
|
||||
//memcpy(palette, pal, 1024);
|
||||
}
|
||||
|
||||
void setcolor(uint8_t index, uint32_t color) {
|
||||
palette[index] = color;
|
||||
palette[index] = color | 0xff000000;
|
||||
}
|
||||
|
||||
uint32_t getcolor(uint8_t index) {
|
||||
|
||||
Reference in New Issue
Block a user