Announcement: Be excellent to each other.


Caravel Forum : Caravel Boards : Development : A question about programming
Page 1 of 2
2
New Topic New Poll Post Reply
Poster Message
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon A question about programming (0)  
I figured that, instead of signing up to a C++ website just to ask a question that will be answered 2 weeks later when I forget about checking it, I would just ask in a forum I regularly visit.

If you really want to hear the story behind the request (if it even qualifies as a "story"), it's in the secret tag. But, let's face it, not even Mario can stay awake when his bro Luigi is telling stories about collecting the Magical Compass and rescuing Princess Eclair.
Click here to view the secret text

. . . what commands can be used to load images from a file, how are they used, and what parameters do they have?
I also would like to know how to just set a pixel to a color, because the unfortunate truth is that I'll probably start with games where the player is one pixel large. I apoligize if anyone here ever has to play such a game.

And why does MVC++EE always debug in a command window? Something tells me I'm already doing something wrong, because I doubt the command window goes fullscreen (let alone show pictures).

____________________________
Also known as ExpHP everywhere else.
09-03-2007 at 02:41 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
schep
Level: Smitemaster
Avatar
Rank Points: 864
Registered: 03-01-2005
IP: Logged
icon Re: A question about programming (+2)  
C++ has no way to do any of the above. One reason for this is that (unlike Java) C++ can be used on computers that don't have fancy things like graphics or a monitor.

However, C++ does have a way of connecting your program to "libraries", which are collections of functions (and data) somebody has programmed to do extra useful things. So if you feel you're ready for a step beyond bare-bones C++, you'll need to choose a library that can do graphics, learn how to attach ("link") it to your program, and then figure out how to use that library's functions.

DROD uses SDL for most of its graphics, input, and sound stuff. I'm not particularly familiar with SDL, but the documentation here looks helpful. Note that the SDL functions are designed for use with C, which can be used in C++, but you'll see structs and pointers everywhere, never classes, methods, or references.

My personal favorite graphics library for C++ is Qt. This one's actually written in C++. Documentation is here.
09-03-2007 at 04:01 AM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
Kevin_P86
Level: Smitemaster
Avatar
Rank Points: 535
Registered: 06-28-2005
IP: Logged
icon Re: A question about programming (+1)  
If you want to make a graphical application, you are looking at one of two things: OpenGL or DirectX, and either may be appropriate depending on what you are making.

The biggest advantage of OpenGL is it is cross-platform - that is, it can run on Windows, Mac OS and even Linux. There are also a number of "wrappers" for OpenGL - such as glut and SDL (DROD uses SDL).

The biggest advantage of DirectX is that it is optimized for windows, and therefore is considerably faster when running under windows. The disadvantage is that it only runs under windows. If you are creating a program with intense 3D graphics, this is probably a better choice, as OpenGL will probably run too slowly.

I personally really like SDL - it makes a lot of things very easy. But again, it depends what you're developing, and what your target audience is.

Hope that helps.

____________________________
+++++[>+++++<-]>[>+++>++++>+++++<<<-]>.>+.>-------.<++++.+++++.

[Last edited by Kevin_P86 at 09-03-2007 04:09 AM]
09-03-2007 at 04:05 AM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
coppro
Level: Smitemaster
Rank Points: 1308
Registered: 11-24-2005
IP: Logged
icon Re: A question about programming (+2)  
The problem is that officially, C++ requires no graphics whatsoever. In console apps, there's no command to clear the screen because C++ doesn't recognize the existence of a screen - only the four standard handles (standard input, standard output, standard error, and standard log). They can be connected to anything. Naturally, this isn't all that great when making complex applications.

Thus we introduce the concept of libraries. They aren't just used for graphics programming, but for everything (see www.boost.org for an example). A library is a collection of precompiled functions and some header files, so that a program can interface with the functions without needing to code them. The standard C++ functions and objects like cout, vector, and fopen are part of the Standard Library - the library that must be included for a compiler to meet standard (note that it doesn't have to be a library in the traditional sense of the word. The compiler doesn't have to link it the way it may another library). While all libraries are technically nonstandard, almost every decent compiler supports two kinds of libraries. Statifc libraries are included in the final executable, and dynamic libraries are loaded into the program by the OS at launch (DLL stands for Dynamic Link Library. On Unix they're called shared objects). Since every platform will include a library for access to nonstandard functions (through nonstandard means), there are a number of libraries designed to use each of this on different platforms. DROD uses SDL (libsdl.org) for it's drawing, and a number of other libraries for other things. A popular command-line library is an old one called ncurses; a Windows version can be found at pdcurses.sourceforge.net. Usually somewhere under the project options, you can instruct the compiler which libraries to include, but the specifics vary from compiler to compiler (and IDE to IDE).

If you want very exacting drawing, OpenGL is a library that has an accompanying graphics card interface, for extremely specific drawing commands. However, it's graphics only, and provides no window structure or input, etc. SDL provides a basic window interface, but you still have to control a lot of the drawing. For instance, there isn't a really easy way to create a button. It also has a way to make it use OpenGL for drawing, but once again, that's pretty advanced. You probably want something like wxWidgets, which is a lot easier to start with.

EDIT: It's also worth noting that wxWidgets has a number of other nice features, such as image loading without another library, and ZIP file handling.

Also, it's a good thing you didn't post this on a dedicated C++ forum, because C++-specific forums tend to look down upon people who don't understand that C++ contains no graphical features.

[Last edited by coppro at 09-03-2007 04:10 AM]
09-03-2007 at 04:05 AM
View Profile Show all user's posts Quote Reply
Maurog
Level: Smitemaster
Avatar
Rank Points: 1501
Registered: 09-16-2004
IP: Logged
icon Re: A question about programming (0)  
Hmm, in Visual C++ you can set the image file as a resouce and have the interface handle the details. That's for accessing, parsing images is a pain, and impossible to find any help on it, but I found a way in the past, and will post some code when I can. Give me like 5 hours.

____________________________
Slay the living! Raise the dead!
Paint the sky in crimson red!
09-03-2007 at 05:54 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
Maurog
Level: Smitemaster
Avatar
Rank Points: 1501
Registered: 09-16-2004
IP: Logged
icon Re: A question about programming (+2)  
Here you go. This is how I managed tiles in C++. There was an image file containing many 64x64 tiles, listed as a resouce with handle IDB_NUMBERS. The code below is used to extract a single tile from the image file and assign it to the control m_test as its bitmap. You can do all sorts of other stuff with CBitmap though...
	CBitmap pBmpTarget;

	int nWidth       = 64;
	int nHeight      = 64;
	
	CBitmap* pBmpSource = new CBitmap();

	pBmpSource->LoadBitmap( IDB_NUMBERS );	// The image resource containing all 64x64 tiles
	pBmpTarget.LoadBitmap( IDB_DUMMY );	// A dummy 64x64 image

	CBitmap* pOldTargetBmp = NULL;
	CBitmap* pOldSourceBmp = NULL;

	CDC      targetDC;
	CDC      sourceDC;

	CDC*     pDC = this->GetDC();
	
	targetDC.CreateCompatibleDC(pDC);
	sourceDC.CreateCompatibleDC(pDC);

	pOldTargetBmp = targetDC.SelectObject(&pBmpTarget);
	pOldSourceBmp = sourceDC.SelectObject(pBmpSource);
	
	// Copy into target a 64x64 square with offset 0 from source with offset 0
	targetDC.BitBlt(0, 0, 64, 64, &sourceDC, 0, 0, SRCCOPY);

	sourceDC.SelectObject(pOldSourceBmp);
	targetDC.SelectObject(pOldTargetBmp);

	sourceDC.DeleteDC();
	targetDC.DeleteDC();

	ReleaseDC(pDC);

	m_test.SetBitmap(HBITMAP(pBmpTarget));


____________________________
Slay the living! Raise the dead!
Paint the sky in crimson red!
09-03-2007 at 10:21 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
coppro
Level: Smitemaster
Rank Points: 1308
Registered: 11-24-2005
IP: Logged
icon Re: A question about programming (+1)  
Resources are a Windows-specific idea of including files as data in the executable. There are specific API calls for loading those files. It is actually something I generally consider a good idea, except in the fact that you either need extra code to load from a local file, or you need to relink every time you change a file (which is a pain, especially in huge projects where the linking alone takes a few minutes).

If you want to take advantage of Windows resources, I recommend that you write your own function to load from a resource, as this can be changed to load from a local file during development, and it can also have different versions for different platforms (improving the portability considerably). Especially when using a cross-platform library that has resource support (wxWidgets comes to mind).

DROD doesn't use resources though - all the game images are stored in drod3_0.dat.
09-04-2007 at 12:27 AM
View Profile Show all user's posts Quote Reply
aztcg7
Level: Master Delver
Avatar
Rank Points: 104
Registered: 03-08-2005
IP: Logged
icon Re: A question about programming (+1)  
On a side note, OpenGL is exclusively for 3D drawing. 3D drawings require an x,y,z and textures and such, with which it modifies for use in drawing a 2D representation on the screen. SDL has options to use OpenGL, for use within programs, but also has 2D programming options, which I believe DROD uses. 2D programming is much simpler, in which you have pictures, which get turned into bitmaps, and then pushed onto the screen however it's programmed. A good tutorial for the introduction of 2D SDL is "Programming Linux Games" by Loki Software with John R. Hall. It used to be downloadable for private use, but I can't find the webpage for it. At any rate, the webpage for the book is nostarch.com/plg.htm and the chapters on SDL are pure gold.

Also, as far as I know, DirectX does both 2D and 3D, but with different interfaces, so you can't mix and match them.

EDIT: I forgot to mention that Programming Linux Games uses C, instead of C++, but it's not difficult to put the functions and such in classes.

____________________________
In other news, :( is a considerably more stylish way to express sarcasm than ;), because everybody uses ;) and I am /indie/. INDIE, I TELL YOU.

[Last edited by aztcg7 at 09-04-2007 04:27 AM]
09-04-2007 at 04:26 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
Briareos
Level: Smitemaster
Avatar
Rank Points: 3516
Registered: 08-07-2005
IP: Logged
icon Re: A question about programming (0)  
aztcg7 wrote:
On a side note, OpenGL is exclusively for 3D drawing.
A lot of games using OpenGL to draw their interface (like most iD Software games) would beg to differ on that one... ;)

(2D is just a special case of 3D, after all...)

____________________________
"I'm not anti-anything, I'm anti-everything, it fits better." - Sole
R.I.P. Robert Feldhoff (1962-2009) :(
09-04-2007 at 09:18 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
aztcg7
Level: Master Delver
Avatar
Rank Points: 104
Registered: 03-08-2005
IP: Logged
icon Re: A question about programming (0)  
I suppose. But it would be much nicer of them if they didn't. Lets say for the sake of argument, that I have an old crummy 2D only graphics card, regardless of how awesome the rest of my computer is. OpenGL requires a 3D environment, which would have to be emulated by my CPU, clogging it for all the important stuff, like logic. Were they simply using 2D dealies, it might be marginally slower than 3D in the case you have a 3D accelerated card, considering card manufacturers have neglected it for 3D stuffs over the last couple of years, but it's much better for my old card.

And I went on a rant. Awesome. Lookie, I'm turning into Kwakstur!

;)

____________________________
In other news, :( is a considerably more stylish way to express sarcasm than ;), because everybody uses ;) and I am /indie/. INDIE, I TELL YOU.
09-04-2007 at 07:18 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
Okay, thanks for the info so far. I had a reply typed up but I left it in a tab for, like, 2 days, so I hadn't sent it.
I do have to admit, it seems wierd that the term for stuff like DirectX is "library." But, then again, many things in C++ have wierd terms, especially "statement," since in language a statement is a definitive and descriptive sentence with a subject and verb, and it may be true or false. I think they should be "commands," because, like a command, they tell the program what to do.

Look at me getting sidetracked . . .

I have a quite a few questions right now, mostly about Maurog's post. Most of my questions are all grouped together in the oversized question 4. I doubt they can all get answered unless somebody has a lot of time on thier hands, but this is the kind of info that, once I have it, I can get started with programming.

First, the general questions:

1) How do I tell the program to use a library with it?
2) What library do you recommend? I plan to start with simple graphics, possibly even ones that use 256 colors.
If that question really just sparks controversy (it seems to have already done so before I even asked), forget it. I think I'll just use what Maurog's using, because if somebody actually answers all the questions about it, I would rather not have them do so in vain.

And for Maurog: Ugh, with question 4 below, I feel so bad asking for so much information. Especially since I have naught but two measly mod points to give in return. But I need the information before I can start programming:

3) Which library are you using?
4) I want some info on the stuff used there. Since I see no class or function definitions there, I have to assume that the below things are included in the library. So this is what I want to know:
Click here to view the secret text


Sigh. If there was an olympic sport for being a burden, then [insert the way-too-predictable second half of the sentence here].
Same with if there were an olympic sport for needless self-criticism at the end of posts.

Wow, two gold medals. To be [proud], or not to be?

____________________________
Also known as ExpHP everywhere else.
09-04-2007 at 08:47 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Briareos
Level: Smitemaster
Avatar
Rank Points: 3516
Registered: 08-07-2005
IP: Logged
icon Re: A question about programming (+2)  
Kwakstur wrote:
Okay, thanks for the info so far. I had a reply typed up but I left it in a tab for, like, 2 days, so I hadn't sent it.
I do have to admit, it seems wierd that the term for stuff like DirectX is "library."
*cough*

But, then again, many things in C++ have wierd terms, especially "statement," since in language a statement is a definitive and descriptive sentence with a subject and verb, and it may be true or false. I think they should be "commands," because, like a command, they tell the program what to do.
There's a big difference between natural languages and programming languages - when was the last time you talked BASIC with someone else? The term statement just means the most basic building block for programs...

And, going by your other questions - are you sure you don't want to start with a language like Java or C# which is similar to C/C++ in syntax, but makes doing most of the things you want to do a lot easier because stuff like loading/writing images and painting to the screen come with their standard libraries and are much easier to use?

The Win32 stuff Maurog wrote about was state-of-the-art ca. in the mid-nineties, and it hasn't gotten a lot better - if you ask me, it's painful to use... :(

I doubt your first programs (or, incidentally, most programs in general) will have to squeeze out every last bit of CPU time available, never mind the problem of making sure you don't produce any memory leaks in your program etc.

____________________________
"I'm not anti-anything, I'm anti-everything, it fits better." - Sole
R.I.P. Robert Feldhoff (1962-2009) :(

[Last edited by Briareos at 09-04-2007 10:31 PM]
09-04-2007 at 10:29 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
schep
Level: Smitemaster
Avatar
Rank Points: 864
Registered: 03-01-2005
IP: Logged
icon Re: A question about programming (+2)  
Kwakstur wrote:
1) How do I tell the program to use a library with it?
No matter what library you use, the answer here usually has four parts:
a) Tell the preprocessor what header file(s) (*.h) from the library to read in.
This is done with a line like: #include <something.h>
Without that, Maurog's sample code will make about as much sense to the compiler as it did to you.

b) Tell the preprocessor where to look for header files.
c) Tell the linker what libraries to link (on Windows, *.lib or *.dll).
d) Tell the linker where to look for library files.

Using a Microsoft IDE, all three of these can be set up in the 'Project Settings' or something which sounds similar. It sounds like Maurog was using things included with the Microsoft compiler, in which case (b) and (d) might not be necessary. For (b), look for the words 'preprocessor'/'include' and put in a list of directories. For (c) and (d), look for the words 'link'/'libraries'.

If you use *.dll (dynamic) libraries, there may be another step or two.
e) Tell the compiler that you intend to use that library dynamically instead of staticly.
f) Make sure the program can find all its DLLs when it runs.

If the libraries came with the Microsoft compiler, chances are that dynamic linking is the default and the DLLs are already installed where every program can find them.

Otherwise, for (e) you'll have to look at each library's documentation (if it comes with both *.lib and *.dll). For (f), DLLs will be found if they're in the same directory as the *.exe you make, or in your windows\system\ directory, or in a directory listed in the PATH environment variable.

09-04-2007 at 11:39 PM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
Since I probably don't have the other things installed, I'm currently looking through the stuff for DirectX. I must say, that website takes forever to load each page.

EDIT: Silly me, if I can play DROD, then SDL must already be installed. I should check that, too.
In fact, they probably all came with the computer (they should), but that doesn't explain why they actually have a download page on those sites. I mean, you would expect every computer has most of them to begin with.

____________________________
Also known as ExpHP everywhere else.

[Last edited by Kwakstur at 09-05-2007 02:25 AM]
09-05-2007 at 02:23 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Syntax
Level: Smitemaster
Rank Points: 1218
Registered: 05-12-2005
IP: Logged
icon Re: A question about programming (0)  
You'll want the actual SDL libraries as opposed to the runtime version though if you want to develop.
09-05-2007 at 02:33 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
coppro
Level: Smitemaster
Rank Points: 1308
Registered: 11-24-2005
IP: Logged
icon Re: A question about programming (0)  
Well, SDL is not developed by Micro$oft. And you would constantly have to download updates to the various libraries, because libraries like SDL are constantly being developed. DROD just includes the library statically, so that it already has all the functions it needs - you will need to download the header files and the static library components also.
09-05-2007 at 02:51 AM
View Profile Show all user's posts Quote Reply
Maurog
Level: Smitemaster
Avatar
Rank Points: 1501
Registered: 09-16-2004
IP: Logged
icon Re: A question about programming (+3)  
For questions 1 to 3 - I was using MFC, which is the Microsoft Foundation Class Library. It basically connects you to every aspect of any Windows operating system which you can control from C++ applications. For example, the code that I gave was within the scope of CWnd class, and will only work from inside a CWnd. A CWnd represents a standard window, but any control, be it a button or a picture or an edit box, derives from CWnd. If you are using Visual C++, you can choose the MFCAppWizard (exe) option to create a base MFC project.

Now for question 4:

It seems like the following things are classes/structures. For both, I want to know what the class is used for, what it's members are (and, of course, I need to know the parameters for functions), and what constructors/destructors it has (if any).
They are: CBitmap and CDC
CBitmap is an MFC class for holding bitmaps. It has a default constructor, and it has some functions for loading bitmaps into it. It doesn't really have any functions except for loading bitmaps and such. It is a basic object that other classes use in their functions.

CDC (standing for Device Context) is a lot more complicated. Think of it as a super-pen, which you can get from a window to draw anything on that window. Any window has a client area on which it can draw, and any control (button etc) is a window. CDC has a million functions, which include everything MSPaint application can do and more. Lines, text, ellipses, images, you name it, it's there, and you can draw it on a window.

I'm not quite sure about nWidth and nHeight. Are they global variables you made, or are they static variables in a class? Or something else?
They are irrelevant, just ignore them. They were supposed to be constants to be used in BitBlt function, but in the example, the sizes were explicitly written as 64.

IDB_NUMBERS and IDB_DUMMY: 1) I'm assuming that those are the names of bitmaps included in the program, and that bitmaps are included in the Resources folder of my solution. Correct me if I'm wrong.
2) If my assumption is correct, then what format should they be?
This is correct. In Visual C++, you can just add resources to your project and give them names. These names become handles you can call them by. The actual resources were a large .bmp file containing tiles for IDB_NUMBERS and a 64x64 pixels blank .bmp file for IDB_DUMMY.

Due to the lack of periods, it seems that the function (or, at least, I /think/ it's a function) ReleaseDC is not actually a member of class CDC, although I still want to know what it's used for.
This is correct. GetDC() and ReleaseDC( CDC* ) are functions of CWnd class. One gets a CDC for the window that called it, and one releases it.

I have no clue what SRCCOPY and HBITMAP are. Period.
And unless one of them tells which tile to load from the source bitmap, then I think I have another question. ;)
SRCCOPY is a system constant DWORD, part of a series which tell the BitBlt function which operation to perform on the target bitmap using the source bitmap. In this case, it just tells to copy the source into the target.
HBITMAP is a CBitmap handle class. When assigning a CBitmap to a control, you don't give the control an actual bitmap, but rather a handle that it can fetch it by.

m_test seems to be an important object of one of the classes here. But since I probably already said the word "assumption" ten times already in this post, I'll just stop guessing and let you just tell me what it is.
m_test is a control, it could be for example a button, or an image control. Remember Minesweeper - it's nothing but a big matrix of such controls. Using the SetBitmap function, you can tell the control what it currently displays - using the Minesweeper example, by right-clicking the button, you assign a CBitmap of a small red flag to the button.

That's about it I think.

____________________________
Slay the living! Raise the dead!
Paint the sky in crimson red!
09-05-2007 at 09:18 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
coppro wrote: Well, SDL is not developed by Micro$oft. And you would constantly have to download updates to the various libraries, because libraries like SDL are constantly being developed. DROD just includes the library statically, so that it already has all the functions it needs - you will need to download the header files and the static library components also.
I guess most programs do it that way for other people's convenience, since I only once needed to download something like this for a program to work (and it was .net framework). But, for the sake of computer space, I'm not statically including libraries in any programs I'm not going to release.

Maurog wrote: A bunch of answers
Thanks a ton. I'll definitely consider this, but it appears that the MFC template is not included in Express Edition. Not to worry, though. I'm checking Microsoft's website for documentation on it so that I can manually include it. Heck, I'll make my own template and rub it in Express' face.
In fact, I should do so for each of the graphics libraries here, just to make my decision process easier.

...

Shoot, I thought that was all I needed. Hang on, I have one* more question:

About what schep said: When I tell it where to look, how do I do so? Do I just tack it on behind the include, or is it separate? And is it the definite directory (C:\Program files\Blahblah\whatever\<header.h>) or the relative directory (.. .. \Blahblah\whatever\<header.h>)?

I'm starting to notice a general trend here about order of stuff. Does the computer, like, go through the preprocessor directives backwards? Because, honestly . . . we always tell it to include files from a namespace/library before we actually tell it what namespace/library to get it from.
Surely I'm not the only one who has ever spent half an hour wondering why the build would not succeed, just to find out that iostream comes before namespace std.

Never mind that paragraph of confusion. I just realized that the files aren't in the namespace. But since they can't be included in a namespace (it would add something that I guess messes up the directive), they are put before it.

*Rules are subject to change.

____________________________
Also known as ExpHP everywhere else.

[Last edited by Kwakstur at 09-05-2007 07:45 PM]
09-05-2007 at 07:20 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
I'm starting to get really frustrated.

Every single thing I read about any of these librarys says to include the header files. NOT A SINGLE ONE bothers to ever tell what these header files are. Even you guys have completely dodged that subject, probably without noticing that you have.
Either I have the absolute crappiest luck with searching the web, or I am once again completely misunderstanding how something works and so once again I am getting frustrated because I'm searching for something that doesn't exist. Sigh, I'm so sick of that happening.

If the reason actually is crappy luck this time, then I really need to know: What are the specific header files I will want to include for each of those libraries?
Because, let me tell you, I tried, and I can't find a single mention of a legit .h file for ANY of the libraries I looked up (which so far is OpenGL, DirectX, and MFC). Quite frankly, I'm not even going to bother looking up any of the others mentioned here; if I get any more frustrated then I am right now, I'll wake up to find my computer in two pieces. Besides, I just looked back through the topic; the only two I haven't looked up are just "wrappers" of OpenGL. Since I can't find anything for OpenGL, they don't sound very promising, anyways.

If I happen to be misunderstanding something again, please, please, set me straight before something fragile (like a cat) comes into my room.
I might as well say that's an exaggeration, because if I don't, somebody else will and I'll end up getting no answer.

____________________________
Also known as ExpHP everywhere else.
09-05-2007 at 11:32 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Kevin_P86
Level: Smitemaster
Avatar
Rank Points: 535
Registered: 06-28-2005
IP: Logged
icon Re: A question about programming (+3)  
If you wish you can provide the entire path in the include directive, i.e.:
#include <c:\program files\...\file.h>

That should work with no problems.

However, a better way is to tell the IDE where to look for included files. I'm not sure if anything's changed in Visual Studio 2005, but in 2003 you can go to Project -> Properties... -> C/C++ -> Additional Include Directories, and include the path(s) there. This will make them available only to this solution. Alternatively, you can go to Tools -> Options -> Projects -> VC++ Directories, select "Include Files" in the "Show directories for:" drop-down list, and add the directories there. This will make these include files available to every solution.

In these cases, you simply need to put:
#include <file.h>
with no path necessary.

The specific files you need to include depends on what you are doing. For example, I will outline the steps to get SDL working. Others should be a similar idea.

1. Download the SDL library. You will need one of the "Source code" items, available from this page.

2. Extract these files anywhere on your computer. The directory doesn't matter. For example, c:\Program Files\SDL\

3. You now need the .lib and .dll files. You can build them youself by opening the .sln file found in the VisualC folder of what you just unzipped, and building it yourself. Alternatively, you can download the appropriate "Development Library" from the same page, which includes pre-built versions. It turns out the source is included in the Development Library, so if you download this you do not need to download the Source code above.

4. Place the .lib files (SDL.lib and SDLmain.lib) somewhere. For example, c:\Program Files\SDL\lib

5. Tell the IDE where to find the SDL include files as described above. In my example, you would provide the directory c:\program files\SDL\include

6. Tell the IDE where to find the SDL .lib file. Either Project -> Properties -> Linker -> General, and add the directory containing the .lib file to "Additional Library Directories" or add it to the VC++ Library Directories in the same way as you could add the include directory, except selecting "Library Files" instead of "Include Files". Then, in Project -> Properties -> Linker -> Input, add SDL.lib and SDLmain.lib to "Additional Dependencies".

7. Tell the IDE that this project will make use of one or more DLL files. Project -> Properties -> C/C++ -> Code Generation, and change "Runtime Library" to "Multi-threaded DLL" or "Multi-threaded Debug DLL" (depending on the active configuration).

8. In your souce file(s) in which you want to use SDL functions, you need to #include<SDL.h>

9. After compiling your program, you need to place SDL.dll in the same directory as the .exe (or, alternatively, in any directory the system PATH variable points to). If you do not do this, the program will compile fine, but running the .exe will complain about not being able to find SDL.dll.

That should be all. A basic introduction to using SDL can be found here. It should be enough to get you started, anyways.

Hope this helps.

____________________________
+++++[>+++++<-]>[>+++>++++>+++++<<<-]>.>+.>-------.<++++.+++++.

[Last edited by Kevin_P86 at 09-06-2007 12:41 AM : forgot a step - my bad]
09-06-2007 at 12:32 AM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
Thank you so much, Kevin. I followed your example for SDL to see if I could at least get a library to work in any circumstances.

I reached a problem: Some persistent Linkage error.

The following is some do-absolutely-nothing program for SDL. I went to copy some code from the SDL guide; I wanted to see if I could successfully build anything. I kept on fixing snytax errors until I finally came to this:
Maincpp.cpp
Click here to view the secret text
Maincpp.h
Click here to view the secret text
You may notice that I'm using some techniques I found elsewhere, from using #ifndef to make directives run once, to clearly distinguishing between "" and <> in #include. Finally, this setup made no syntax errors. But it did get this:
LINK : fatal error LNK1561: entry point must be defined
I did already try to fix it with various options under Linker, such as the #define TL_LINKED you see there, as well as trying many different combinations of the three possible Entry points and the 8 or so possible Subsections in the linker for the IDE. But all efforts that fixed one problem caused another.
I tried my best to reset the program to what you initially said, so hopefully, you can guess the current settings of the program, so you should know all the circumstances.

Do you know how to combat this?

Thankfully, I got programming anyways; the program I plan to use graphics in is currently being coded to use iostream, but I can't wait until I can use SDL (or any other library, if I find them to be better).

____________________________
Also known as ExpHP everywhere else.
09-08-2007 at 07:14 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Briareos
Level: Smitemaster
Avatar
Rank Points: 3516
Registered: 08-07-2005
IP: Logged
icon Re: A question about programming (+2)  
Kwakstur wrote:
The following is some do-absolutely-nothing program for SDL.
Well, have you tried the international standard of do-something-programs?

hello.c:
#include <stdio.h>

main()
{
	printf("hello, world\n");
}
If that doesn't compile, link and run something must be quite stuffed up in your compiler/linker/IDE configuration...

EDIT: Googling for 'LNK1561 SDL' yielded this: Setting Up SDL on Visual C++ Express 2005 which says that by default Visual C++ Express is set up to build managed (aka .NET) applications, which is not going to make SDL happy. (Adding all those libraries to AdditionalDependencies should do it - that's about the default list of libraries VS 2005 Professional uses, and those libraries are essential...)

As it includes step-by-step instructions to make VS C++ Express work properly I'd say give them a whirl...

np: Kraftwerk - Elektro Kardiogramm (Minimum-Maximum (Disc 2))

____________________________
"I'm not anti-anything, I'm anti-everything, it fits better." - Sole
R.I.P. Robert Feldhoff (1962-2009) :(

[Last edited by Briareos at 09-08-2007 07:50 PM]
09-08-2007 at 07:42 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
Noooo! For what must be the 10th time, I typed up some post expressing my gratefulness and saying that I'm sure no more problems worth bringing up will pop up. And for the 10th time, I had to delete such a post when I found another problem.

I followed the steps outlined in that PDF. And it made the program successfully build the solution. I was thinking "yay! For the first time ever, I built a solution using at least one command from at least one library!"
But then I tried using Debug. I got this:

Unable to start program 'c:\documents and settings\main\my documents\visual studio 2005\projects\pleasework\debug\pleasework.exe'
The application has failed to start because the application configuration is incorrect.

At first, I realized that there was no file with that name (I have not created an executable), so I tried using Compile, which I figured would make the .exe. And it did. But that didn't fix the problem. Both using Debug and trying to open the .exe with My Computer still bring up the same message.

What might be causing this? And will I ever get to just thank you all, stop asking questions, and let this topic die while we continue on with our lives?
---
EDIT: I just noticed that I was using files from another project in my program, so I went and copied the code in the files, made new header and cpp files with the same code, made changes to the #include stuff accordingly, and removed the old ones.
This for some reason generated a conflicting library warning, so I had to use /NODEFAULTLIB msvcrt.lib in the command line. I hope this does not generate problems.
---

____________________________
Also known as ExpHP everywhere else.

[Last edited by Kwakstur at 09-09-2007 10:56 PM]
09-09-2007 at 10:52 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
Rather than have two threads, I'm bringing this one back up.

I'm trying Qt now; that's the response I got when I asked on the MSDN forums. But it seems like it just won't build correctly no matter what I do in VC++2005. So I'm trying to build through the command prompt (which I will now call the CP).

I've used the CP before, but previous experience didn't help much. Basically, I am trying to get an exe out of Qt's tutorial program for qmake. After 6-7 hours of research/work, I have found several programs to use to cover all the intermediate steps. To summarize what would've been the next three paragraphs, I'll tell what I am using:

-Notepad: Yes, I am using a plain text editor, not anything like Visual Studio. I use notepad to make .cpp, .h, and .pro files.
-The "expand" CP command: Although expand was made for archives, it can be used on any file (with effects similar to copy and paste). By expanding a program to system32, it becomes a command for the CP (I had to expand the three programs below). If this method is flawed, tell me.
-qmake.exe (from Qt): I use this to turn a .pro file into a Makefile (as well as a Makefile.Release and a Makefile.Debug).
-nmake.exe (from pSDK): You use this on the Makefiles. I'm hoping that it will produce the .exe I'm longing for.
-g++.exe (from MinGW): Whatever it does, it needed to be expanded, because the makefile tells nmake to use it.

So that's my background. Here's my problem: When I use nmake on the files, it works all nice and fine . . . up until it can't find lQtGui4 or lQtCored4. Those are libraries, but here's the problem: nmake is telling the truth; those exact libraries don't exist. In Qt\4.3.1\lib, I have files with similar names:
libQtGui4.a, libQtCore4.a, QtGui.prl, QtCore.prl, QtCored.prl
Surely, I must do something to these. I probably need to find another program that makes .lib files out of them. But research is hard. I mean, one time, I mispelled a search term, and the resulting word just so happenned to appear in a page about expanding a program to system32. But my luck streak seems to have ended, so I ask you: What must I do to these libraries?

____________________________
Also known as ExpHP everywhere else.
10-07-2007 at 12:33 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
coppro
Level: Smitemaster
Rank Points: 1308
Registered: 11-24-2005
IP: Logged
icon Re: A question about programming (0)  
A Makefile is a special file that tells make (or in your case, nmake) how to build a program. However, if you are being asked to use any component of MinGW, you're drifting into the Gnu Compiler Collection, which means, for starters, that what you're building will likely not be compatible with Visual C++, due to name mangling and other issues.

From the looks of it, you are using the wrong nmake. The one you want is the Microsoft one (I think). It's probably in your Visual C++ directory somewhere.
10-07-2007 at 01:10 AM
View Profile Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
Why would the one in Visual Studio be any better? As I have previously stated, I'm currently trying to build without Visual Studio. You see, qmake automatically sets it up to work with Qt; I don't have to worry about the possibility that I'm forgetting something important in my project properties.

____________________________
Also known as ExpHP everywhere else.

[Last edited by Kwakstur at 10-07-2007 03:03 AM]
10-07-2007 at 03:02 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
coppro
Level: Smitemaster
Rank Points: 1308
Registered: 11-24-2005
IP: Logged
icon Re: A question about programming (0)  
You have to use Visual Studio, since that's what you're coding with. Mixing libraries compiled with MinGW and those compiled with Visual Studio are not nessecarily compatible. Rereading what you said, it seems that Qt is trying to compile itself with G++, so unfortunately you can't use qmake. The thing is, you need to compile it for Visual Studio, not nessecarily with the Visual Studio interface.

This tutorial seems to have the instructions you need. If you just download the patch, run qconfigure and then run nmake, it should work.

The importance here is the difference between the IDE and the compiler. The IDE is the program that opens up and actually has the editor and source highlighting and projects and whatnot. It is strictly optional. The compiler is the program that actually does the work of turning the code into a program or library. You need to make sure that you use the Visual C++ compiler, or else the library may not work with other programs compiled with it.
10-07-2007 at 03:19 AM
View Profile Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
As g++ is in MinGW, and qmake is in Qt, I don't see how it could be coding in Visual Studio. Quite frankly, other than the fact that it has the ability to compile (meaning it has its own compiler), I don't even understand how Visual Studio could be more than an IDE. What, is Qt trying to use Visual Studio's built-in compiler?

At the very least, I'm glad I don't have to use Build Debug Libraries. You know, I played through entire game of Sonic Rush Adventure (imo best Sonic platformer ever), and it was building the 9th entry by the time I got back to my computer. Who could blame me for thinking it doesn't work?


Anyways, I decided to try the download anyways (no use being the antagonist), and it appears that when I use qconfigure.bat, I will have to choose between MinGW (g++) and Visual Studio (msvc2005). [abrupt change in topic]Usually, in a multipoint post like this, it's hard to tell what I'm really expecting a response to, so I'll make it completely and blatantly obvious . . . [abrupt revert] My main question is this: After choosing MinGW or Visual Studio, will I still be free to use either the command prompt or the Visual Studio IDE, or will only one of them work? And if am stuck with the command prompt, will I still need to use the nmake from Visual Studio?


As far as Visual Studio goes, I have Express Edition, and Readme43 has some wierd complication listed for it:
  After this, you can start compiling (not using cmd.exe) with the help of
  'Visual Studio .NET 2005 Command Prompt'
:wacko I swear, this is just becoming stupid.


____________________________
Also known as ExpHP everywhere else.

[Last edited by Kwakstur at 10-07-2007 05:22 AM]
10-07-2007 at 05:21 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
coppro
Level: Smitemaster
Rank Points: 1308
Registered: 11-24-2005
IP: Logged
icon Re: A question about programming (0)  
After choosing MinGW or Visual Studio, will I still be free to use either the command prompt or the Visual Studio IDE, or will only one of them work? And if am stuck with the command prompt, will I still need to use the nmake from Visual Studio?
Yes and no. If you use MinGW, you will have to use MinGW to compile programs using Qt. If you use Visual Studio (from the command line), you will be free to use the IDE.
10-07-2007 at 05:07 PM
View Profile Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 385
Registered: 05-05-2006
IP: Logged
icon Re: A question about programming (0)  
Sorry I have so many questions. I feel like some 4 year old asking his parents about everything. There is just no satisfying him.

Anyways, the following error popped up when it went to build:
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cl.EXE' : return code '0xc0000135'

Researching it led me to something I'm not quite sure I can do (specifically, edit Qt's Makefile of undetermined location), so I'm a bit lost here.

____________________________
Also known as ExpHP everywhere else.
10-07-2007 at 07:18 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Page 1 of 2
2
New Topic New Poll Post Reply
Caravel Forum : Caravel Boards : Development : A question about programming
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.