• 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
Graphic_Programmer

My Screenshot Problem with SDL and OpenGL in C

4 posts in this topic

Hi,
I wanted to write screen saver function for my mother OpenGL Suface yesterday.
First, i thinked this is very easy!
I wrote SDL_SaveBMP(screen,"deneme.bmp");
The End..
That can be comic for you but unluckily it did not be. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
The program showed an error message me and it was grotesque for me.
Then, I found a function from a web site but does not work correctly.When it saved a bmp file, it only showed a color on all surface.The color was color of glClearColor function.
The Screenshot Code:
[CODE]
int Screenshot(char *filename, SDL_Surface *screen)
{
SDL_Surface *temp;
unsigned char *pixels;
int i;

if (!(screen->flags & SDL_OPENGL))
{
SDL_SaveBMP(temp, filename);
return 0;
}

temp = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000FF, 0x0000FF00, 0x00FF0000, 0
#else
0x00FF0000, 0x0000FF00, 0x000000FF, 0
#endif
);
if (temp == NULL)
return -1;
pixels = malloc(3 * screen->w * screen->h);
if (pixels == NULL)
{
SDL_FreeSurface(temp);
return -1;
}
glReadBuffer(GL_FRONT_AND_BACK);
glReadPixels(0, 0,screen->w, screen->h,GL_RGB , GL_UNSIGNED_BYTE, pixels);
for (i=0; i<ekran->h; i++)
memcpy(((char *) temp->pixels) + temp->pitch * i, pixels + 3*screen->w * (ekran->h-i-1), screen->w*3);

free(pixels);
SDL_SaveBMP(temp, filename);
SDL_FreeSurface(temp);
return 0;
}
[/CODE]
Not : For first error the reason is not different between screen,"filename" and "filename",screen.SDL_SaveBMP and Screenshot are different fuctions.
Thanks. Edited by Graphic_Programmer
0

Share this post


Link to post
Share on other sites
For starters, get rid of the "ekran" variable and use screen or temp in its place.

Look at this thread: [url="http://www.gamedev.net/topic/351860-taking-screenshots-using-glreadpixels/"]http://www.gamedev.n...g-glreadpixels/[/url]

Check what is the value of gluErrorString(glGetError()) after the call to glReadBuffer. Overall, the code seems legit, but I'm not an OpenGL expert by any means.

Do you draw something in OpenGL? When do you call this Screenshot function?

Edit:
GL_FRONT_AND_BACK seems to be illegal value for glReadBuffer. Try with GL_FRONT_LEFT instead. Quoting the [url="http://www.opengl.org/sdk/docs/man/xhtml/glReadBuffer.xml"]documentation[/url]:
[quote]mode
Specifies a color buffer.
Accepted values are
GL_FRONT_LEFT,
GL_FRONT_RIGHT,
GL_BACK_LEFT,
GL_BACK_RIGHT,
GL_FRONT,
GL_BACK,
GL_LEFT,
GL_RIGHT, and
GL_AUXi,
where i is between 0 and the value of GL_AUX_BUFFERS minus 1.
...

Nonstereo double-buffered configurations have only a front left and a back left buffer[/quote] Edited by dilyan_rusev
0

Share this post


Link to post
Share on other sites
[quote name='dilyan_rusev' timestamp='1344706588' post='4968451']
For starters, get rid of the "ekran" variable and use screen or temp in its place.

Look at this thread: [url="http://www.gamedev.net/topic/351860-taking-screenshots-using-glreadpixels/"]http://www.gamedev.n...g-glreadpixels/[/url]

Check what is the value of gluErrorString(glGetError()) after the call to glReadBuffer. Overall, the code seems legit, but I'm not an OpenGL expert by any means.

Do you draw something in OpenGL? When do you call this Screenshot function?

Edit:
GL_FRONT_AND_BACK seems to be illegal value for glReadBuffer. Try with GL_FRONT_LEFT instead. Quoting the [url="http://www.opengl.org/sdk/docs/man/xhtml/glReadBuffer.xml"]documentation[/url]:
[quote]mode
Specifies a color buffer.
Accepted values are
GL_FRONT_LEFT,
GL_FRONT_RIGHT,
GL_BACK_LEFT,
GL_BACK_RIGHT,
GL_FRONT,
GL_BACK,
GL_LEFT,
GL_RIGHT, and
GL_AUXi,
where i is between 0 and the value of GL_AUX_BUFFERS minus 1.
...

Nonstereo double-buffered configurations have only a front left and a back left buffer[/quote]
[/quote]
Thank you very much for your help! Me too not a expert of OpenGL but sure, you know it better than me becuse i am new in OpenGL and my English isn't very good to understand everything.
Oh, i am an idiot [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] First, I might say thats:
Already, I called Screenshot function with screen surface and drew something to screen.The problem weren't them.
When i tried GL_FRONT_LEFT, i made it just and i have a question: why doesn't it be when i tried GL_FRONT_RIGHT instead?
What is different between LEFT and RIGHT? Does it mean front face and back face. I will try all of them. Edited by Graphic_Programmer
0

Share this post


Link to post
Share on other sites
To be honest, I do not know what is the difference between left and right. It must be some feature of OpenGL that I have never used. If you set-up OpenGL with [url="http://sdl.beuc.net/sdl.wiki/SDL_GL_SetAttribute"]SDL_GL_SetAttribute[/url]( SDL_GL_DOUBLEBUFFER, 1 ) before [url="http://sdl.beuc.net/sdl.wiki/SDL_SetVideoMode"]SDL_SetVideoMode[/url], then you have two buffers: front and back.

Simply put, you draw continuously to the back buffer, and once everything is done, you show it to the user (with [url="http://sdl.beuc.net/sdl.wiki/SDL_GL_SwapBuffers"]SDL_GL_SwapBuffers[/url]).

glReadBuffer is an OpenGL function. Its documentation says that double-buffered applications have only two buffers (obviously), and gives you the names. I guess they arbitrarily chose left, and not right. What matters is that what is currently displayed to your user should be in the front buffer, and therefore this is the buffer you load into the OpenGL's state machine. Again, according to the glReadBuffer documentation, the "mode" parameter for the front buffer should be GL_FRONT_LEFT. And that is why I said that you should perhaps use it that way.

As for the rest, I honestly do not understand what you ask (or if you are asking something).

I asked about how you call the Screenshot function, because it depends on the OpenGL state. If it is called before anything is displayed (i.e. before SDL_GL_SwapBuffers), then it will be empty (the value of glClearColor). It should also be called after OpenGL has been properly initialised and before SDL is shut down.
0

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