Alright, I have spent a lot of time on this one, so I need some help. I like the ability to draw pixels directly to the screen, sometimes I do this to trace the path of objects for debugging etc. In SDL 1.2 you could do something sort of like this :
//make screen
SDL_Surface * screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//make surface
SDL_Surface * pSurface = SDL_CreateRGBSurface( SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0x000000ff,0x0000ff00,0x00ff0000,0xff000000);
//get the pixels
Uint32 * pixels = (Uint32 *)pSurface->pixels;
//set a pixel to red
pixels[ x + ( y * pSurface->w ) ] = SDL_MapRGB(pSurface->format, 255, 0, 0);
//blit to screen
SDL_Rect offset = {0,0,0,0};
SDL_BlitSurface( pSurface, NULL, screen, &offset );
This would result in a red pixel being displayed, you could make a simple line across the screen with a loop. Now SDL2 is really blowing my mind at the moment, here is what I've got:
//setup
window = SDL_CreateWindow("test",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,SCREEN_WIDTH, SCREEN_HEIGHT,SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 32, 32, 32, 255);
//make surface and texture
SDL_Surface * pSurface = SDL_CreateRGBSurface( 0, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0x000000ff,0x0000ff00,0x00ff0000,0xff000000);
SDL_Texture * pTexture = SDL_CreateTexture( renderer,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_STREAMING,SCREEN_WIDTH,SCREEN_HEIGHT);
//from texture into surface
SDL_LockTexture(pTexture, NULL, &pSurface->pixels, &pSurface->pitch);
//get the pixels
Uint32 * pixels = (Uint32 *)pSurface->pixels;
//set a pixel to red
pixels[ x + ( y * pSurface->w ) ] = SDL_MapRGB(pSurface->format, 255, 0, 0);
//surface back to texture?
SDL_UnlockTexture(pTexture);
//clear the screen, then copy the texture to framebuffer, then update
SDL_RenderClear( renderer );
SDL_Rect renderQuad = {0,0,0,0};
SDL_RenderCopy( renderer, source, clip, &renderQuad );
SDL_RenderPresent(renderer);
This does nothing, except to fill the screen with the RenderDrawColor. What am I doing wrong..?
SDL_RenderCopy
you are renderingsource
(where is that from?), whereas you were changing the pixel on thepTexture
texture. \$\endgroup\$