• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tolito

SDL 2.0 - Edit Renderer Pixels

7 posts in this topic

When I was storing the screen as an SDL_Surface, I could multiply colors to it like so:

   Uint32 *pixels = (Uint32 *)screen->pixels;

    unsigned int x, y;

    for(y=0;y<screen->h;y++) {

        for(x=0;x<screen->w;x++) {

            // Code to edit each pixel here.

        }

    }

I am migrating my code to work with SDL_Textures again, which requires using an SDL_Renderer. I am familiar with using SDL_RenderCopy and all of those functions, but I'm not sure how to go about editing the individual pixels rendered to an SDL_Renderer, and this is necessary. Does anyone have any suggestions on how to do this? Thanks!

 

0

Share this post


Link to post
Share on other sites

You could keep a copy of the texture in an SDL_Surface, modify the surface as you used to, then SDL_UpdateTexture to get the pixels into the final texture. You should create the texture with SDL_TEXTUREACCESS_STREAMING to tell SDL that you plan on updating the texture frequently.

2

Share this post


Link to post
Share on other sites

Thanks for the reply! Actually, I am using SDL_RenderCopy to copy textures to the screen, which is of type SDL_Renderer. Instead of updating every texture each frame, I want to edit the pixels of the renderer itself, basically the final version of the screen. I am trying to avoid using an SDL_Surface since this will be calculated each frame and I want to do all of this in the GPU. Creating a surface that is a copy of the renderer, multiplying the colors there, converting the surface to a texture, and using SDL_RenderCopy again to put the edited colors back on the renderer would work, but it seems like there is a more efficient way of doing that. Is there a way to access and edit the pixels of an SDL_Renderer itself? Thanks again!

0

Share this post


Link to post
Share on other sites

The only way to do this all on the GPU would be to use the OpenGL renderer and do the post-processing in a shader.

 

There's no way to get at the pixels of the current frame outside of a shader. All the details of what a frame looks like are hidden behind the abstract SDL_Renderer. It could be a pixel buffer for software rendering, or a set of VBOs, etc., which would mean there is no pixel representation of the final image until it's actually flushed to the GPU.

1

Share this post


Link to post
Share on other sites

Thanks again! Since no pixel representation can be found, it sounds like my idea of storing said pixels as an SDL_Surface after they have been copied to the renderer is not a possibility. The only efficient possibility for doing this may be copying the to-be-blitted region of each texture, multiplying to the copy, rendering the copy to the SDL_Renderer, and destroying the copy. Doing this effectively is all over my head, though. Should I keep using SDL_Surfaces for everything and do the multiplication and rendering there, then storing as a texture and rendering that to the renderer at whatever scale?

0

Share this post


Link to post
Share on other sites

Update:

 

For my new multiplication function, I simply did this:

    SDL_Rect r={0,0,XRES,YRES};
    SDL_SetRenderDrawBlendMode(screen,SDL_BLENDMODE_MOD);
    FillRect(screen,&r,color);
This multiplies the new color to the screen without the need for accessing and editing the screen pixels, multiplying to them one by one. Since this is why I was needing to access the renderer pixels, this is no longer a problem.
2

Share this post


Link to post
Share on other sites

Excellent solution. That will keep all the work on the GPU. I didn't realize you were multiplying all pixels by the same value, or I might have thought to suggest something like that.

 

Glad you got it sorted!

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0