- Provant el shader crt-pi

This commit is contained in:
2024-06-27 18:37:30 +02:00
parent 37a9e981a5
commit 16d8d5c5b5
2 changed files with 23 additions and 19 deletions

View File

@@ -21,8 +21,8 @@
#include <SDL2/SDL_opengl_glext.h>
#endif
const int WIN_WIDTH = 640;
const int WIN_HEIGHT = 480;
const int WIN_WIDTH = 1024;
const int WIN_HEIGHT = 768;
const int WORLD_WIDTH = 320;
const int WORLD_HEIGHT = 240;
@@ -81,8 +81,11 @@ GLuint compileShader(const char* source, GLuint shaderType) {
//std::cout << "Compilando shader:" << std::endl << source << std::endl;
// Create ID for shader
GLuint result = glCreateShader(shaderType);
const char *sources[2] = { shaderType==GL_VERTEX_SHADER?"#define VERTEX\n":"#define FRAGMENT\n", source };
// Define shader text
glShaderSource(result, 1, &source, NULL);
glShaderSource(result, 2, sources, NULL);
// Compile shader
glCompileShader(result);
@@ -118,9 +121,6 @@ GLuint compileProgram(const char* vtxFile, const char* fragFile) {
std::string source((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
/*const char *sources[2] = { "#define VERTEX\n", source.c_str() };
glShaderSourceARB(shader, 2, sources, NULL);*/
vtxShaderId = compileShader(source.c_str(), GL_VERTEX_SHADER);
f=std::ifstream(fragFile);
@@ -159,6 +159,8 @@ void presentBackBuffer(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* bac
GLint oldProgramId;
// Guarrada para obtener el textureid (en driverdata->texture)
//Detach the texture
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderClear(renderer);
@@ -291,6 +293,7 @@ int main(int argc, char **argv){
while ( ! done ) {
//Render to the texture
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_SetRenderTarget(renderer, texTarget);
SDL_RenderClear(renderer);