Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TLN_SetRenderTarget parameter
#5
Oh $*%)#... yes I forgot to put TLN_Init() back after commenting out the framebuffer stuff...

Ok I've made those changes, now it runs, but when I quit the loop, it again prints "Segmentation fault" at the console. So it's great that it's running now, but an error on quit is obviously not good.

And do I need to "SDL_RenderPresent" at the end?

Here's my current code;

Code:
//Using SDL and standard IO
#include<SDL2/SDL.h>
#include <stdio.h>
#include <Tilengine.h>

//Screen dimension constants
const int SCREEN_WIDTH = 320;
const int SCREEN_HEIGHT = 240;

int main( int argc, char* args[] )
{
//The window we'll be rendering to
SDL_Window* window = NULL;

//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
return 1;
}

//Create window
   window = SDL_CreateWindow( "Tilengine with scaling and sound", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
   if( window == NULL )
   {
       printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
       return 1;
   }

   const int hres = 400;
   const int vres = 240;
   int frame = 0;
   /*
   const int pitch = hres * sizeof(int);
   void* framebuffer;
   // init and set framebuffer
   TLN_Init (hres, vres, 2, 80, 0);
   framebuffer = malloc (pitch * vres);
   TLN_SetRenderTarget ((uint8_t*)framebuffer, pitch);
   */

   TLN_Init (hres, vres, 2, 80, 0);
   SDL_Renderer* renderer = SDL_CreateRenderer (window, -1, 0);
   uint8_t* rt_pixels;
   int rt_pitch;
   SDL_Texture* backbuffer;
backbuffer = SDL_CreateTexture (renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH,SCREEN_HEIGHT);

//Main loop flag
bool quit = false;
//Event handler
SDL_Event e;
//While application is running
   while( !quit )
   {
       //Handle events on queue
       while( SDL_PollEvent( &e ) != 0 )
       { //User requests quit
           if( e.type == SDL_QUIT )
               quit = true;
           if( e.type == SDL_KEYDOWN )
           {
               if(e.key.keysym.sym == SDLK_ESCAPE)
                   quit = true;
           }

           SDL_LockTexture (backbuffer, NULL, (void**)&rt_pixels, &rt_pitch);
           TLN_SetRenderTarget (rt_pixels, rt_pitch);
           TLN_BeginFrame (frame);
           TLN_UpdateFrame (frame++);
           SDL_UnlockTexture (backbuffer);
           SDL_RenderCopy (renderer, backbuffer, NULL, NULL);
           SDL_RenderPresent (renderer);
       }
   }

   /* deallocate */
   //free (framebuffer);
   TLN_Deinit ();

//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();

return 0;
}
Reply


Messages In This Thread
TLN_SetRenderTarget parameter - by Domarius - 07-18-2018, 01:56 AM
RE: TLN_SetRenderTarget parameter - by megamarc - 07-18-2018, 03:15 AM
RE: TLN_SetRenderTarget parameter - by Domarius - 07-18-2018, 10:27 AM
RE: TLN_SetRenderTarget parameter - by megamarc - 07-18-2018, 03:33 PM
RE: TLN_SetRenderTarget parameter - by Domarius - 07-18-2018, 08:11 PM
RE: TLN_SetRenderTarget parameter - by megamarc - 07-19-2018, 03:44 PM
RE: TLN_SetRenderTarget parameter - by Domarius - 07-19-2018, 09:25 PM
RE: TLN_SetRenderTarget parameter - by megamarc - 07-21-2018, 03:56 PM
RE: TLN_SetRenderTarget parameter - by Domarius - 07-22-2018, 12:21 AM
RE: TLN_SetRenderTarget parameter - by megamarc - 07-24-2018, 01:52 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)