Skip to main content
Rollback to Revision 3 - Edit approval overridden by post owner or moderator
Source Link
amziraro
  • 446
  • 1
  • 3
  • 18

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is alphablue, second is redgreen, third is green,red and fourth is bluealpha. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is alpha, second is red, third is green, and fourth is blue. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is blue, second is green, third is red and fourth is alpha. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is bluealpha, second is greenred, third is redgreen, and fourth is alphablue. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is blue, second is green, third is red and fourth is alpha. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is alpha, second is red, third is green, and fourth is blue. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitchpitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is blue, second is green, third is red and fourth is alpha. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is blue, second is green, third is red and fourth is alpha. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

You can use SDL_LockTexture and SDL_UnlockTexture for write only access to a texture created with the SDL_TEXTUREACCESS_STREAMING flag. Lock, write, unlock, then use SDL_RenderCopy to blit to the screen.

Create the buffer with SDL_CreateTexture (modify to you liking):

SDL_Texture* buffer = SDL_CreateTexture(renderer,
                           SDL_PIXELFORMAT_BGRA8888,
                           SDL_TEXTUREACCESS_STREAMING, 
                           800,
                           600);

Lock with SDL_LockTexture:

SDL_LockTexture(buffer,
                NULL,      // NULL means the *whole texture* here.
                &pixels,
                &pitch);

Where pixels is a int * and pitch is the width of a row of pixels in bytes.

Write your pixel data to pixels. You won't have any of the convenient SDL functions to do this. Just plonk the data in, one pixel after the other until you have done them all. Make sure you write with the correct PIXELFORMAT, otherwise the colours will come out wonky. (In SDL_PIXELFORMAT_BGRA8888, the first byte is blue, second is green, third is red and fourth is alpha. Leave alpha at 255 unless you want transparency)

Clean up with SDL_UnlockTexture:

SDL_UnlockTexture(buffer);

Then you can RenderCopy this texture as normal:

SDL_RenderCopy(renderer, buffer, NULL, NULL);

This assumes the buffer is the same size as your window.

Note you will have to modify this for your own use case.

added 4 characters in body
Source Link
amziraro
  • 446
  • 1
  • 3
  • 18
Loading
Source Link
amziraro
  • 446
  • 1
  • 3
  • 18
Loading