|
Hi all,
I am new to windows programming, I am converting my OpenGL program written in Linux platform into Windows platform. I have used glutIdleFunc() for idle callback func, now I would like to use the same callback func as idle func in Windows platform. How can I use a func as idle func in Windows without using GLUT.
Any help would be greatly appriciated.
Thanks
Scody
|
|
|
|
|
I guess it ultimately depends on how you write your own OpenGL program. You can still use GLUT and freeGLUT under Windows platforms, that keeps your code mostly identicle between platforms. The other is to insert your code into it's own call system.
Since freeglut is "free" you can also examine the code to see how the idle function was used. http://freeglut.sourceforge.net/docs/api.php[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
If I setup a static variable like this:
[CODE]
// .h file
class DisplayLine
{
static SolidBrush s_solidBrush;
...
};
[/CODE]
and initialize it like this:
[CODE]
// .cpp file
SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0));
[/CODE]
and then in the draw() routine do this:
[CODE]
void DisplayLine::Draw(Graphics *pGraphics)
{
// Draw the text
pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &s_solidBrush);
}
[/CODE]
that the text will not draw due to the brush. Weird.
What am I doing wrong? Why is the brush not getting initialized?
I even tried adding this:
s_solidBrush.SetColor(Color(255, 0, 255, 0));
but that didn't help.
-- modified at 18:51 Monday 9th October, 2006
|
|
|
|
|
>>the text will not draw due to the brush. Weird.
How do you know this??
Mark
|
|
|
|
|
Because if I creat a brush in the draw() method it works fine.
This works:
void DisplayLine::Draw(Graphics *pGraphics)
{
Font font_big(L"FIXEDSYS", 18, FontStyleBold, UnitPixel);
Font font_small(L"FIXEDSYS", 12, FontStyleBold, UnitPixel);
StringFormat sFormat = new StringFormat();
sFormat.SetAlignment(textAlign);
sFormat.SetLineAlignment(lineAlign);
SolidBrush a_solidBrush(Color(255, 0, 255, 0));
// Set text to display
wchar_t buf[20+1] = { 0 };
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lineText.c_str(), (int)lineText.length(), buf, 20);
// Draw the text
pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &a_solidBrush);
}
}
Even if I make the s_solidbrush public, it still does not work.
|
|
|
|
|
is this...
[CODE]
// .h file
class CduLine
{
static SolidBrush s_solidBrush;
...
};
actually this? (what is the CduLine class?)
[CODE]
// .h file
class DisplayLine
{
static SolidBrush s_solidBrush;
...
};
In CPP file, outside of any function...
SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0));
|
|
|
|
|
Yes... My mistake... I was changing names to make things clear.
the definition is at the top of the file outside of any functions.
|
|
|
|
|
Geez at least SetColor should have worked
Beats me but I'll keep looking at it...I would expect it to work!
Mark
|
|
|
|
|
by my understanding of what i've found in msdn the folowing code should redirect the output of "ping www.google.com" to a file...and well...it doesn't. Where did i go wrong?
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
ULONG rc;
HANDLE hFakeStdOut = CreateFile(
"C:\\myfile.txt",
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if(hFakeStdOut==INVALID_HANDLE_VALUE)
{
printf("CreateFile failed with %d\n",GetLastError());
return;
}
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESTDHANDLES;
StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
StartupInfo.hStdOutput = hFakeStdOut;//GetStdHandle(STD_OUTPUT_HANDLE);
StartupInfo.hStdError = hFakeStdOut;//GetStdHandle(STD_ERROR_HANDLE);
char sCurDir[1023];
GetCurrentDirectory(1023,sCurDir);
if (!CreateProcess( NULL,
"ping www.google.com",
NULL,
NULL,
TRUE,
NULL,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
printf("Failed with %d\n",GetLastError());
}
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc))
rc = 0;
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(hFakeStdOut);
I've been reading about this for about an hour now and i can't get it. Please help
|
|
|
|
|
eusto wrote: if (!CreateProcess( NULL,
"ping www.google.com",
NULL,
NULL,
TRUE,
NULL,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
printf("Failed with %d\n",GetLastError());
}
I think that you should specify the full path to ping.exe (always a good habit, ask any *nix person, it prevents a command hijack), and put that path into the first parameter. Put the parameters to ping.exe (www.google.com) as the second parameter and see if that works.
I have had situations in the past where specifying everything as the command line fails, but breaking them up works. Dunno why, but try it.
Also, did you try using pipes as suggested in the MSDN article located at http://msdn.microsoft.com/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]? Maybe it works with pipes but not with normal files? I would get the pipes version working first.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Thanks but the full path is not the problem. Braking the args and actual module name did not work either.
This sucks msdn says that a handle can be anything that supports Read() and Write() so a hadle to a file created by CreateFile shoul work. I realy don't get it
|
|
|
|
|
The handle needs to be inheritable:
try
SECURITY_ATTRIBUTES SecurityAttributes;
SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor = NULL;
SecurityAttributes.bInheritHandle = TRUE;
HANDLE hFakeStdOut = CreateFile(
"C:\\myfile.txt",
GENERIC_WRITE,
FILE_SHARE_WRITE,
&SecurityAttributes,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
|
|
|
|
|
Thanks...but it still does not work
|
|
|
|
|
if u want to redirect the out put u can use any of the following ways...
SHELLEXECUTEINFO stInfo = {0};<br />
stInfo.fMask = SEE_MASK_NOCLOSEPROCESS;<br />
stInfo.cbSize = sizeof(SHELLEXECUTEINFO);<br />
stInfo.lpVerb = _T("open");<br />
stInfo.lpFile = _T("cmd");<br />
stInfo.lpParameters = _T("/c ping www.google.com > c:\\result.txt");<br />
stInfo.nShow = SW_SHOW;<br />
ShellExecuteEx( &stInfo );<br />
WaitForSingleObject(stInfo.hProcess, INFINITE);
or
STARTUPINFO StartupInfo;<br />
PROCESS_INFORMATION ProcessInfo;<br />
ULONG rc;<br />
memset(&StartupInfo, 0, sizeof(StartupInfo));<br />
StartupInfo.cb = sizeof(STARTUPINFO);<br />
if (!CreateProcess( _T("c:\\windows\\system32\\cmd.exe"),<br />
_T("/c ping www.google.com > c:\\result.txt"),<br />
NULL,<br />
NULL,<br />
TRUE,<br />
NULL, <br />
NULL, <br />
NULL,<br />
&StartupInfo,<br />
&ProcessInfo ))<br />
{<br />
printf("Failed with %d\n",GetLastError()); <br />
}<br />
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);<br />
CloseHandle(ProcessInfo.hThread);<br />
CloseHandle(ProcessInfo.hProcess);
nave
|
|
|
|
|
|
Learn2LikeIt wrote: Exactly how does switch case work?
Exactly the way the tutorial describes it.
Keep at, hopefully it will begin to sink in. Also you might try this site[^]. But don't expect to actually "know" C++ in 21 days.
led mike
|
|
|
|
|
led mike wrote: But don't expect to actually "know" C++ in 21 days.
How how how how true .
|
|
|
|
|
Hi,
Could you specify what exactly gives you headache, please?
Regards
|
|
|
|
|
O.K well since I seem to be in the right forums I'm gonna have alot of questions scince I've never really used C++ or any other scripting language before. I hope I'm not a bother. Anywho I was wondering how functions can be applied, like can they have random things in them or do they follow a specific set? Generally I'd like to know a tad more on functions.
I'm a true failure.
|
|
|
|
|
Can you explain what do you need?
|
|
|
|
|
Learn2LikeIt wrote: I've never really used C++ or any other scripting language before.
First, C++ isn't a scripting language. Second, what books on C++ have you read?
The evolution of the human genome is too important to be left to chance.
|
|
|
|
|
How do i setup timers in a console application? Is it possible? does anyone know any tutorial on this matter?
Thanks
|
|
|
|
|
It is fairly simple. Take a look at the MSDN documentation for CreateTimerQueueTimer()
led mike
|
|
|
|
|
Thanks! Didn't know about this one
|
|
|
|
|
See here.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|