I need help setting up an example app....

  • Thread starter Thread starter Brett Baisley
  • Start date Start date
B

Brett Baisley

At school, we do all of our coding in emacs, but I am trying to get the
example apps working at home using Visual C++.net.

In the example, there are 4 .cpp files (canvas.cpp, main.cpp, myDisplay.cpp
and tween.cpp) a header file (canvas.h) and a makefile that compiles it for
linux.

The tween.cpp is the main file, and it only contains inludes statements to
the other files.

How do I set this up so that I can compile it and run it using VC++.net on a
Windows machine?

Thanks!

Brett
 
Brett Baisley said:
At school, we do all of our coding in emacs, but I am trying to get the
example apps working at home using Visual C++.net.

In the example, there are 4 .cpp files (canvas.cpp, main.cpp, myDisplay.cpp
and tween.cpp) a header file (canvas.h) and a makefile that compiles it for
linux.

The tween.cpp is the main file, and it only contains inludes statements to
the other files.

How do I set this up so that I can compile it and run it using VC++.net on a
Windows machine?

Does your example use a simple character-at-a-time output model, i.e.
std::cout?

If so choose File->New->Project from the menu. Then highlight the "Visual
C++ Projects" "folder" in the tree on the left and scroll down the window on
the right to the "Win32 Console Project" icon and click it once. Then in the
edit box labeled "Name" type a short name for your project. Note the
location of your project's files which is specified two lines below. Then
click the OK button. Now click the "Application Settings" hyperlink and
choose "Empty Project". Make sure the ATL and MFC options are NOT selected.
Finally click the Finish button to create your example project.

Now copy your source and header files to your project's location. Now choose
Project->Add Existing Item from the menu. Either select all of the source
and header files at once or one at a time but make sure you have added them
all to the project. Then click Build->Build Solution from the menu.

If all goes well, you will have an executable which you can run in the
normal ways or by using either of the Start options from the debug menu.

If all does not go well, post again. News server willing, someone is almost
always here.

Regards,
Will
 
It didn't work. I get a ton of errors. Here are just a few of them.

c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\stdlib.h(251):
error C2381: 'exit' : redefinition; __declspec(noreturn) differs
c:\Program Files\Microsoft Visual Studio
..NET\FrameworkSDK\include\GL\glut.h(146) : see declaration of 'exit'
c:\Documents and Settings\Brett\My Documents\Visual Studio
Projects\myTween\myDisplay.cpp(11): error C2146: syntax error : missing ';'
before identifier 'cvs'
c:\Documents and Settings\Brett\My Documents\Visual Studio
Projects\myTween\myDisplay.cpp(11): error C2501: 'Canvas' : missing
storage-class or type specifiers
c:\Documents and Settings\Brett\My Documents\Visual Studio
Projects\myTween\myDisplay.cpp(11): error C2501: 'cvs' : missing
storage-class or type specifiers

I dunno why. If i use the compiler in linux, everything works fine at
school.

Anything else to try?
 
Its an OpenGL based app, so maybe I don't have it set up right? I did what I
could find on the net, I got all the files, and put them in the lib folder
of C++, where they say to put it.

I was going by a ppt I found online, but the one slide that has C++.NET info
was in chinese, the rest was all in english, and I can't read it. I think I
have to add "opengl32.lib, glut32.lib and glu32.lib" to some project
settings, but I dunno where that is.
 
Brett Baisley said:
It didn't work. I get a ton of errors. Here are just a few of them.
...

First, I should point out that when I asked:

"Does your example use a simple character-at-a-time output model, i.e.
std::cout?" I was trying to determine if you were doing something that would
port easily. If I had known that you were trying to port an OpenGL
application I would have let your question go right on past me. :-)

But as I am already involved, and as I have been spending some time with my
senior-year niece getting her up to speed on VS.Net, I downloaded your
example. :-)

Your example does what I have rarely seen done - it uses #include to include
other source files rather than header files. I'll pass on whether this is a
good idea or not and simply point out that in order for this to work with
VS.Net's build mechanism, you'd have to remove all of the source files from
the project _except_ rectangle.cpp which will include the others.

The crux of your problem, I think, is that the header file

GL/glut.h

is nowhere to be found on a standard Win32 installation (at least it is not
on this XP/Pro/SP1box).

I found it here:

http://www.xmission.com/~nate/glut.html

So, I downloaded the ZIP file, copied the header (.h file), the import
library (.lib file) and dynamic link library (.dll file) to the project
directory and modified the source of the rectangle example slightly:

//---------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include "glut.h"

#define WINDOW_HEIGHT 256
#define WINDOW_WIDTH 256

#include "init.cpp"

#include "myMouse.cpp"

#include "myDisplay.cpp"

#include "main.cpp"
//---------------------------------------------

Then I built the project.

Surprsingly, it built without errors!

It almost worked - that is it displayed an ugly black frame window.

If, however, you activate the OpenGL window by clicking the window's "client
area" (i.e. neither the borders nor the caption) with the mouse, the sample
will draw a white rectangle, about half as large as the black container, and
centered within it.The click is required as well if you move the window.

That may get you started. You'll need to do some leg work to get the example
to work without the cludge of the mouse click.

Regards,
Will
 
I did exactly what you said, but I get the following error when I try to
compile it:

c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\stdlib.h(251):
error C2381: 'exit' : redefinition; __declspec(noreturn) differs

Any ideas why?

Brett
 
Brett Baisley said:
I did exactly what you said, but I get the following error when I try to
compile it:

c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\stdlib.h(251):
error C2381: 'exit' : redefinition; __declspec(noreturn) differs

Any ideas why?

It happened to me too until I changed the order of the header files as in my
post. It compiled, I didn't investigate.

Regards,
Will
 
I did it your way, and it works the way it should.

Now I am wondering how to do it the right way. Like I tried adding all of
the existing files just as they are to the solution in VC++.NET, but when I
build the solution, I get errors.

So then I took out all of the include statements and tried that, but the
same thing. It seems to me, that when I compile the solution, it compile
each file separately, therefore it can't find things located from one of the
other files.

How do I fix that problem? So that I can hit F5 and it run normally? Is
there a way to tell it what file to run first or something?

Thanks for all your help by the way!

Brett
 
Brett Baisley said:
I did it your way, and it works the way it should.

I love it when things work.
Now I am wondering how to do it the right way. Like I tried adding all of
the existing files just as they are to the solution in VC++.NET, but when I
build the solution, I get errors.

It is far more typical to

1) put related functions in a module
2) include the requisite headers at the top of a module
3) include several modules in a project

than to use the include mechanism to generate a single module that does
everything. Now there may be a good reason why your prof did that or he
could be a bonehead, I dunno. I've got even money on the latter possibility.
:-) Perhaps someone else will weigh in on the topic here.
So then I took out all of the include statements and tried that, but the
same thing. It seems to me, that when I compile the solution, it compile
each file separately, therefore it can't find things located from one of the
other files.

That's to be expected because VS.Net tries to compile them individually but
none can compile except the one which includes the headers that declare the
GL functions that are referenced through out the code.
How do I fix that problem? So that I can hit F5 and it run normally?

There should be nothing special that you have to do. In fact, even though
the project that I created has only one source file, I can open up main.cpp,
put a breakpoint there, hit F5 and have the IDE break as soon as it gets
there.

What looks weird to my eyes though, is a console project that creates a
window. A windowed application under Win32 has a different structure, at the
heart of which is a loop which dispatches messages from Windows and from
other applications. The extra click to activate the application is probably
a direct result of not having that structure.

I should tell you, though, that I am at expert at none of graphics in
general, OpenGL in particular, or cross platform portability issues. Perhaps
you'll find some help at the site wich contains the glut library.
Thanks for all your help by the way!

You are welcome.

Regards,
Will
 
I don't really understand what you meant by:
1) put related functions in a module
2) include the requisite headers at the top of a module
3) include several modules in a project
but thats ok.

This is a OpenGL program, it doesn't use any Microsoft code for windows. It
makes its own. The click is actually there on purpose to demonstrate how
input from a mouse in OpenGL works. If you look at the points example, you
would see that it actually makes a 20x20 pixel rectangle using the point on
the window of the mouse click as its starting point. Its kinda cool.

I was just sick of the lab computers, they never work right, so I wanted to
get this working at home, so I can work on my homework here instead of the
lab.

I am still not sure how to get it working so that F5 will build and run the
program, but now at least I can manage. To me, all files included in the
solution should be compiled as one big thing, so as long as they are all
listed in the solution, they should be able to find/reference each other.
But that might not be how it works.

Thanks again. You were a big help!
 
Brett Baisley said:
I don't really understand what you meant by:
but thats ok.

This looks weird to my eyes:

#include <stdio.h>
#include <stdlib.h>
#include "glut.h"

#define WINDOW_HEIGHT 256
#define WINDOW_WIDTH 256

#include "init.cpp"

#include "myMouse.cpp"

#include "myDisplay.cpp"

#include "main.cpp"

The way I see it, the source files init, myMouse, myDisplay and main are
each modules in their own right. They should be compiled separately. The way
the example is written, a change to anything requires a recompilation of
everything. No sane person who uses a compiler for much of the day would
adopt such a ridiculous style. In the real world modules and projects get
big in a hurry. The last thing you want to be doing is to be recompilng the
entire project to fix every bug or to make every change. That's why I called
your prof a bonehead.

Take the main module:

main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE |
GLUT_RGB);
glutInitWindowSize(WINDOW_WIDTH,
WINDOW_HEIGHT);
glutInitWindowPosition(100,150);

glutCreateWindow("OpenGL window");

glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);

myInit();
coordInit();

glutMainLoop();
}

It looks weird roo. That's because it references external functions, e.g.
glutInit(), and constants, e.g. GLUT_SINGLE, yet there is no way these names
can be declared. No C or C++ compiler could successfully compile this
module. However, if it were rewritten like so

#include <stdio.h>
#include <stdlib.h>
#include "glut.h"

#define WINDOW_HEIGHT 256
#define WINDOW_WIDTH 256

main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE |
GLUT_RGB);
glutInitWindowSize(WINDOW_WIDTH,
WINDOW_HEIGHT);
glutInitWindowPosition(100,150);

glutCreateWindow("OpenGL window");

glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);

myInit();
coordInit();

glutMainLoop();
}

then those names would be declared before they are referenced and the module
could compile separately. If you change the source files of the sample in
this way then they each could be added to the project individually. The IDE
would know to compile modules needing recompilation and not compile the
others.
This is a OpenGL program, it doesn't use any Microsoft code for windows.

Ah, to be young. :-) Whatever it is, GLUT is a layer _on top of_ the native
windowing system. On Windows, you code to GLUT, GLUT codes to the Graphics
Device Interface (GDI).
The click is actually there on purpose to demonstrate how
input from a mouse in OpenGL works. If you look at the points example, you
would see that it actually makes a 20x20 pixel rectangle using the point on
the window of the mouse click as its starting point. Its kinda cool.

OK, I'll accept that it is just a teaching device. But in my view, there is
no use in porting code if to do so is to scream out loud that the author
(not you!!! - I mean your prof or the author of GLUT ) doesn't know or care
about the native behaviors of the platform. If you obsure the OpenGL window
by dragging another window over it and then uncover the OpenGL window it
does not know enough to repaint itself. Instead it contains the remnants of
other windows. That looks ugly and unprofessional.

That's what I was referring to when I mentioned the structure of windowed
programs and the work left to do to complete a proper port.
I was just sick of the lab computers, they never work right, so I wanted to
get this working at home, so I can work on my homework here instead of the
lab.

Yup. That's exactly like the perspective of my niece.
I am still not sure how to get it working so that F5 will build and run the
program, but now at least I can manage. To me, all files included in the
solution should be compiled as one big thing, so as long as they are all
listed in the solution, they should be able to find/reference each other.
But that might not be how it works.

No, this is definitely not how it works, not with MS VS.Net, not with
Borland's C++ Builder. Each source file gets compiled independently.
Nevertheless, there should be no problem with a one file project
(rectangle.cpp) as long as the other files are in the same directory. It
works here.

Regards,
Will
 
Ok, Thanks for all of your help. This was very informative for me, as I am
fairly new to both OpenGL and C++.net.

This was the first example we did, kinda like the Hello World ones. It
doesn't do much, and there are many ways to improve it. That is why there is
no repaint methods when you move a window over it, you have to click the
mouse, etc. Its just a basic illustration. We only spent a day or so on it,
then we moved to the canvas class. Its more powerful.

The last question is when I just have the rectangle.cpp file, and I compile
that, it works fine. But what happens if I make any changes to any of the
other files? Will they get compiled as well? I can't do it manually, that
would lead back to the problem of when it was added to the project, and it
would produce errors.
 
Back
Top