First create a texture
https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)
Then set the render target to the texture
https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)
Then you draw stuff as normal, set the target to NULL then draw the texture you created.
NOTE: Untested
If you want to make your own renderer you gota go learn OpenGL, here is some starting codes
Code:
#include <SDL2/SDL.h>
#include <GL/gl.h>
int main( int argc, char* args[] )
{
if( SDL_Init( SDL_INIT_EVERYTHING ) != 0 )
{
//error
}
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 8 );
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
SDL_Window* window = SDL_CreateWindow( “Test Window”,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_OPENGL
);
SDL_GLContext GLContext = SDL_GL_CreateContext( window );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
glViewport( 0, 0, 800, 600 );
/* change to the projection matrix and set our viewing volume. */
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 800, 600, 0, -1, 1 );
/* Make sure we’re chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );
/* Reset The View */
glLoadIdentity();
glPushMatrix();
SDL_Event* event = new SDL_Event;
bool quit = false;
while( !quit )
{
while( !SDL_PollEvent( event ) )
{
if( event->type == SDL_QUIT )
quit = true;
}
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
glPushMatrix();
glBegin( GL_TRIANGLE_STRIP );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glVertex3f( -100, -100, 0.0f );
glVertex3f( 100, -100, 0.0f );
glVertex3f( -100, 100, 0.0f );
glVertex3f( 100, 100, 0.0f );
glEnd();
SDL_GL_SwapWindow( window );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
SDL_Quit();
return 0;
}
samleo wrote:
mr_tawan wrote:
Have you tried remove the following code ? :
Code:
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);
Yes, I tried. But the bug persist, just a little visible.
AlexRou wrote:
Yeah it looks like a scaling bug, you can either use OpenGL directly and make your own renderer or you can try rendering to a fixed size texture then show that and see if it scales right.
And how I do that? Sorry, I’m new to SDL2.
Code:
Code:
Code: