Archived

This topic is now archived and is closed to further replies.

HWND and HDC problem...

This topic is 5649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have an app that loads opengl and everything it uses the whole client are for the viewport but i want to putput the fps using TextOut from win32 api.. do i use the same handle and device context ? or same handle different dc ?? i tried both they won''t work...
Metal Typhoon

Share this post


Link to post
Share on other sites
quote:
Original post by Metal Typhoon
why ? it means i can''t use win32api over ogl''s ?


You actually can''t, at least not directly.
quote:
MSDN wglUseFontBitmaps
In the current version of Microsoft''s implementation of OpenGL in Windows NT and Windows 95, you cannot make GDI calls to a device context that has a double-buffered pixel format. Therefore, you cannot use the GDI fonts and text functions with such device contexts. You can use the wglUseFontBitmaps function to circumvent this limitation and draw text in a double-buffered device context.

Share this post


Link to post
Share on other sites
I don''t know if this helps, but you could put the framerate in the title of the window if you''re not in fullscreen mode.


  
// Copy the frames per second into a string to display in the window title bar

sprintf(strFrameRate, "Current Frames Per Second: %d", int(framesPerSecond));

// Set the window title bar to our string

SetWindowText(g_hWnd, strFrameRate);


But to actually draw the text in your scene I''d go with IndrectX''s suggestion. NeHe has great tutorials for fonts and stuff.

Share this post


Link to post
Share on other sites
i knew that stealth but thx .. i want it on the client area.. i tried nehe's but he led some stuff without explaining...


    
GLuint base;

void LoadFont ()
{
HFONT Font;
HFONT Oldfont; // he never explained why use oldfont...


base = glGenLists(96);

font = CreateFont ( -24,0,0,0,FM_BOLD,FALSE,FALSE,FALSE,
ANSI_CHARSET,OUT_TT_PRECI,CLIP_DEFAULT_PRECI,
ANTIALIASED_QUALITY,DEFAULT_PITCH ,"Courier New");

wglUseFontBitmaps (hdc,32,96,base);
SelectObject (hdc,font);
}
that all i understood... he said he was gonna explain arguments... bah.. can someone explain what that is




Metal Typhoon





[edited by - Metal Typhoon on June 26, 2002 2:56:44 PM]

Share this post


Link to post
Share on other sites
First, the code you posted is incomplete. You need to select the font before you can use it in wglUseFontBitmaps and you need to delete it after you''re done. And you need old font so that you can select it back to the DC. You can''t delete a font (or any other object) that is selected in a DC.

P.S. any chance you can decrease the height of your signature? It grabs too much attention IMHO.

Share this post


Link to post
Share on other sites
quote:
Original post by IndirectX
First, the code you posted is incomplete. You need to select the font before you can use it in wglUseFontBitmaps and you need to delete it after you''re done. And you need old font so that you can select it back to the DC. You can''t delete a font (or any other object) that is selected in a DC.

P.S. any chance you can decrease the height of your signature? It grabs too much attention IMHO.


now u made things clear..... heheh ok i''ll decrease it sir...
so to complete that i need to do

oldfont = (HFONT)SelectObject (hdc,font);
when wgl...
then select oldfont
DeleteObject (hdc,font);

right ??

what about the second part.. about the print...


Metal Typhoon

Share this post


Link to post
Share on other sites
What you want to do is call your Print function with any number of arguments, like so:

Print("This %s is %d", str, 10);

Now can you retrieve all arguments and combine them with the format string? vsprintf does just that. It takes three parameters: destination string, format string, and the va_list pointer. That pointer points to the first argument that your Print function received. As vsprintf goes throught the format string, it reads the current argument and advances va_list pointer to the next one. To put it differently, va_list is sort of a pointer into an array of function arguments. The exact workings of va_list are pretty complicated, and you don''t have to know them if you don''t want to. Just remember that vsprintf takes a va_list that points to your arguments and converts them to string.

How can you point a variable of type va_list to the arguments? You use va_start macro. It takes two arguments: the va_list variable to initialize and the last known parameter to your function. All parameters are placed in the stack one after another, and knowing the last parameter you can advance to the memory where the first variable parameter is stored.

Once you initialized a va_list variable with a call to va_start, you can pass it to vsprintf and you''ll have a formatted string.

va_end is supposed to clean up va_list, but I haven''t seen an implementation in which va_end does something useful. Just call it after you''re done with the va_list variables.

va_list is a variable type, more exactly, it''s a disguised pointer.

Share this post


Link to post
Share on other sites
There''s a load of info about variable arguments in MSDN. Just pop the word va_list into the index and enjoy. It also has info on all Win32 API functions like CreateFont.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites