|
Open-GL is a nice library for people who want to do basic gaming in c++. I mean the library is good to start with line drawing and in the mean time you can end in rich particle system that gives the effect of fog, blast, burn etc
|
|
|
|
|
i want to make a line in c++
and want to know how to do so
and which header files i should include and the complete code.
NISHCHAY
|
|
|
|
|
Okay sure, no problem.
You need to create a windowed or a dialog app, handle the WM_PAINT message, then use the MoveToEx[^] and LineTo[^] functions.
You should #include <windows.h>
There's a million examples already around. You can google for and find them yourself with very little effort.
|
|
|
|
|
Cant i make it by using graphics and pixels if anyone has the idea please tell
|
|
|
|
|
Could you be more specific please?
I'm not using sound, nor is the line drawn using Vegemite-sandwiches!
The line is drawn using pixels and (obviously) graphics!
If you'd like to use graphics.h (Are you using TurboC?) and would like to calculate the position of the individual pixels themselves, you should look up lineDDA or Bresenham or if you'd like it anti-aliased, the Wu Anti-Aliasing algorithm.
There's a million examples already out there. As a programmer, one of your fundamental skills (and tasks) is that of researching!
Go on, have a look it's not that hard. - If you want to code the line function yourself, you should be prepared to read some older code, since for the most part this is a problem that is solved using pre-existing functions, like the ones I linked you to. Functions that will work anywhere, regardless of the BitDepth or resolution of the display monitor. They are also optimized, that is to say they DO-NOT call Pixel(x,y,col) for each point in the line - they'll be a squillion times faster than anything you write yourself - many will also be seamlessly hardware-accelerated.
|
|
|
|
|
when i am using the dda algorithm it shows some errors like setpixel() should have a prototype
how to over come that.
|
|
|
|
|
|
it shows that the setpixel() function used to set pixel(point) for drawing the line, should have prototype.
|
|
|
|
|
What are the exact errors?
|
|
|
|
|
I asked you to provide the exact errors. You did not do so.
I will not help further.
This code will draw 2 lines in a window. You need to link to wingdi32.lib (wingdi32.a if using gcc)
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Code::Blocks Template Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC winHDC;
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_PAINT:
winHDC = GetDC(hwnd);
MoveToEx(winHDC, 0, 0, NULL);
LineTo(winHDC, 100, 100);
MoveToEx(winHDC, 0,100, NULL);
LineTo(winHDC, 100, 0);
ReleaseDC(hwnd, winHDC);
return 0;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
modified 20-Jun-12 5:20am.
|
|
|
|
|
Hard to say when you are so vague.
What are the exact errors?
[EDIT:] And the lines of code that cause them
|
|
|
|
|
For simple, 2D graphics (in Windows), look for tutorials on using the Windows GDI[^].
|
|
|
|
|
I have a basic MFC dialog based app so I am definitely using MFC. The official documentation says, "Non-MFC projects can select Use Standard Windows Libraries to link to various Win32 libraries that are included when you use MFC".
The implication is that you could not build / link / run an MFC application if you chose this compiler option, right? However, you can build and run an MFC application with this option.
What I want to know is, what is really going on or why does an MFC application work? If I use this option can I be free of MFC DLL dependencies? I have spent some time googling this, but I can't find any answers to this question.
|
|
|
|
|
Hi Deep,
Your understanding is almost correct. From visual studio project settings we can select 3 options "Use Standard Windows Libraries", "Use MFC in a Static Library"and "Use MFC in a Shared DLL".
The first one[Use Standard Windows Libraries] is used when we had an application or a dll that did not require MFC class or framework support. For example a console application or pure c++ libraries or a win32 application or a C application etc.
The second and third options are used where we need MFC class or framework support e.g: MFC dialog application, MFC SDI or MDI application or applications using CString etc.
The difference between "Use MFC in a Static Library"and "Use MFC in a Shared DLL" is given below in simple sentence.
If you need to run your application in another computer that did not had a Visual Studio run time, you should choose static library other wise use shared dll. And you can find more difference between these two from net
http://msdn.microsoft.com/en-us/library/1ez7dh12(v=vs.80).aspx[^]
http://stackoverflow.com/questions/2652679/regular-dll-using-mfc-shared-vs-mfc-statically-linked[^]
|
|
|
|
|
If my understanding is correct, then why can I build and run an MFC based Dialog application using the standard windows libraries? I have actually set this application to use the standard libraries and hit build and run and it does.
So why does this work?
|
|
|
|
|
Because an MFC project will automatically include any dependent MFC libraries.
|
|
|
|
|
Ok, thanks that explains that. So is this linked version closer to the MFC-Static mode or shared DLL mode?
|
|
|
|
|
I think the majority of the standard libraries are DLL's as they are installed by default on all Windows systems.
|
|
|
|
|
Thanks for all your help. I think I understand now. I would assume an MFC application compiled with Standard Windows Libraries would still be dependent upon various MFC dlls such that the end users machines might still need the VC redistributable package installed, where as the Static MFC linking gets by that requirement. In other words, going with Standard Windows Libraries buys me nothing unless I am genuinely MFC free.
|
|
|
|
|
Yes, I think that's about it.
|
|
|
|
|
I'm trying to debug a single threaded C++ application. When the program reaches to a breakpoint, the thread state pass to "1". Then, when I press F10 (step-over), the program just continue and it doesn't go to the next statement.
|
|
|
|
|
This is often an indication that the debug database is out of step with the source; try a full rebuild and see if that improves things.
|
|
|
|
|
Either what Richard said, or you're trying to debug multi-threaded code as if it were single-threaded. You will need to freeze and thaw threads appropriately (one of the many things) if it were multi-threaded.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
hello guys... There is this folder which I really don't like to be displayed in my project/solution. When it is opened, I have to scroll all the way down to look for my desired files. Now I know how it can be disabled ( Tools -> Options -> Text Editor-> C/C++ -> Advanced ). But I want to know that how will it affect my projects in future. Although I read this article but still I could not get the idea. Any input is welcome. Thanks.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
If you don't want to see a "folder" in your solution, just remove it from said solution? or "unload" it from the solution ?
Or am I missing something else ?
Watched code never compiles.
|
|
|
|