# SDL_GetVideoInfo and ofstream

## Recommended Posts

I've been reading through "Focus on SDL" and one of the functions I'm learning about is SDL_GetVideoInfo(), yet im programming in c++ and have been using ofstream instead of fprintf (I think I'm right in saying that is C). Problem is when I use ofstream to print the results to a txt I'm getting the wrong results. This is the code:
g_pVideoInfo = SDL_GetVideoInfo();
std:: ofstream VIDEOlog;
VIDEOlog.open("VIDEO Logfile.txt");
VIDEOlog << "-Video Information:\n\n" <<
"-hw_available:\t\t" << g_pVideoInfo->hw_available << "\n" <<
"-wm_available:\t\t" << g_pVideoInfo->wm_available << "\n" <<
"-blit_hw: \t\t" << g_pVideoInfo->blit_hw << "\n" <<
"-blit_hw_CC: \t\t" << g_pVideoInfo->blit_hw_CC << "\n" <<
"-blit_hw_A: \t\t" << g_pVideoInfo->blit_hw_A << "\n" <<
"-blit_sw: \t\t" << g_pVideoInfo->blit_sw << "\n" <<
"-blit_sw_CC: \t\t" << g_pVideoInfo->blit_sw_CC << "\n" <<
"-blit_sw_A: \t\t" << g_pVideoInfo->blit_sw_A << "\n" <<
"-blit_fill: \t\t" << g_pVideoInfo->blit_fill << "\n" <<
"-video memory(in K): \t" << g_pVideoInfo->video_mem << "\n" <<
"-bits per pixel: \t" << g_pVideoInfo->vfmt->BitsPerPixel << "\n";
VIDEOlog.close();


And the results for this are:
Quote:
 -Video Information: -hw_available: 0 -wm_available: 1 -blit_hw: 0 -blit_hw_CC: 0 -blit_hw_A: 0 -blit_sw: 0 -blit_sw_CC: 0 -blit_sw_A: 0 -blit_fill: 0 -video memory(in K): 0 -bits per pixel:
Any help would be greatly appreciated. Am I wrong to use ofstream in this situation?

##### Share on other sites
How do you know the results are wrong?

fprintf is part of C++ too. You can use C functions in C++ if you like. Try both and compare the output.

##### Share on other sites
Quote:
 Original post by KylotanHow do you know the results are wrong?fprintf is part of C++ too. You can use C functions in C++ if you like. Try both and compare the output.

I'm sure I have than 0kb maximum video memory lol and it doesnt even print out the colour format, in the example in the book the guys results were mostly = 1 whereas all mine are 0 except 1, and I'm fairly sure that cant be right, I could be wrong of course. That's what has brought me to believe they're probably not right bt i still need a lot to learn :)

And I know you can use C functions etc but there's alot to take in and I feel more comfortable with ofstream atm, although I'll try using fstreamf as you suggest to see what I get.

##### Share on other sites
I think the problem is because SDL_VideoInfo uses bitfields for a lot of its members (see here).

I'm not too familiar with those, but try this:

VIDEOlog << "-Video Information:\n\n" <<	    "-hw_available:\t\t" << (g_pVideoInfo->hw_available == 1) << "\n" <<	    "-wm_available:\t\t" << (g_pVideoInfo->wm_available == 1) << "\n" <<            // etc.

Only add the comparisons to the fields that have :1 to the right (see link above). For example, video_mem should be printed as usual.

##### Share on other sites
Generally speaking, there should be no problem writing the information to a C++ stream object.
Quote:
And the results for this are:

Quote:
 -Video Information:-hw_available: 0-wm_available: 1-blit_hw: 0-blit_hw_CC: 0-blit_hw_A: 0-blit_sw: 0-blit_sw_CC: 0-blit_sw_A: 0-blit_fill: 0-video memory(in K): 0-bits per pixel:
What's the expected output? Also, what do you get if you use C library functions (e.g. printf()) instead?

[Edit: Too slow x3.]

##### Share on other sites
Quote:
 Original post by Gage64I think the problem is because SDL_VideoInfo uses bitfields for a lot of its members (see here).I'm not too familiar with those, but try this:VIDEOlog << "-Video Information:\n\n" << "-hw_available:\t\t" << (g_pVideoInfo->hw_available == 1) << "\n" << "-wm_available:\t\t" << (g_pVideoInfo->wm_available == 1) << "\n" << // etc.Only add the comparisons to the fields that have :1 to the right (see link above). For example, video_mem should be printed as usual.

It shows the exact same results. I ran it on my laptop also, dif OS etc shows exactly the same results. And I also use fprintf and still the same results lol

@JYK:
I believe this little test pretty much tells me what my system is capable of when it comes down to SDL, for example hw_available == 1 would be telling me I can draw in hardware mode as oppose to software mode which my 8800gt is capable of, hope I'm getting this right, I hate not being so sure haha So yeah i expect my system to be capable of most if not all of these things so they should be at 1 I believe.
Considering all this and it giving the same results on my laptop I must have some fault with my code somewhere or other hmm

Thanks for the feedback btw guys :)

##### Share on other sites
I just ran a similar test on my system, and got the same results.

A couple of things to note from the link I gave earlier:

Quote:
 video_memTotal amount of video memory in Kilobytes, should be accessed only if hw_available == 1, otherwise it is equal to 0

That explains the video memory.

Also:

Quote:
 SDL_GetVideoInfo ... contains information on either the best available mode if called before SDL_SetVideoMode or the current video mode if called after SDL_SetVideoMode.

though on my system only current_w/y were different, the other fields were still 0 (except for wm_available, which was 1).

##### Share on other sites
Quote:
Original post by Gage64
I just ran a similar test on my system, and got the same results.

A couple of things to note from the link I gave earlier:

Quote:
 video_memTotal amount of video memory in Kilobytes, should be accessed only if hw_available == 1, otherwise it is equal to 0

That explains the video memory.

Also:

Quote:
 SDL_GetVideoInfo ... contains information on either the best available mode if called before SDL_SetVideoMode or the current video mode if called after SDL_SetVideoMode.

though on my system only current_w/y were different, the other fields were still 0 (except for wm_available, which was 1).

Lol so maybe I'm getting the correct results then, It's the guys results in the book that are confusing me now, his were:

Quote:
 Video Information:hw_available? 1wm_available? 1blit_hw? 1blit_hw_CC? 1blit_hw_A? 0blit_sw? 1blit_sw_CC? 1blit_sw_A? 0blit_fill? 1video memory(in K)? 36864bits per pixel? 16

I'm in the very early stages of learning SDL btw, things may become clearer once I learn a few more things lol

I get the same results whether SDL_GetVideoInfo is called either before or after too btw

##### Share on other sites
You might be able to get hardware acceleration by changing the video backend. For instance, on Windows about a year ago the default backend was moved from Direct2D to GDI. You can force SDL to choose a particular backend like so. Do be aware that each backend has trade-offs - critically hardware acceleration does not imply speed increases.

##### Share on other sites
Quote:
 Original post by rip-offYou might be able to get hardware acceleration by changing the video backend. For instance, on Windows about a year ago the default backend was moved from Direct2D to GDI. You can force SDL to choose a particular backend like so. Do be aware that each backend has trade-offs - critically hardware acceleration does not imply speed increases.

hey nice, thanks, I'm getting similar results I initially expected now:

Quote:
 -Video Information:-hw_available: 1-wm_available: 1-blit_hw: 1-blit_hw_CC: 1-blit_hw_A: 0-blit_sw: 1-blit_sw_CC: 1-blit_sw_A: 0-blit_fill: 1-video memory(in K): 253960-bits per pixel:

## 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

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627651
• Total Posts
2978397

• 10
• 12
• 22
• 13
• 33