PDA

View Full Version : Shell + OpenGL window



repie
09-23-2006, 04:59 AM
Hello,
I did a class which contains simulation data.
I'd like to create a main which first opens a shell (i ll put my simulation parameters in it),
then creates an OpenGL window drawing the results.
I used some tutorials about opengl and I ve been able to draw some objects etc... But I still don't know how to use class methods in the main
using cout or cin for example (need a shell).
I realy don't know if i must use glu, glut, or glui, i'm realy lost among them.
Thanks.

k_szczech
09-23-2006, 05:40 AM
I guess you'll need glut (or freeglut). GLU is just a set of helpful functions, and GLUI is for creating user interface inside OpenGL window (buttons, lists, etc. are drawn using OpenGL).

repie
09-23-2006, 06:24 AM
Yes i thought so, but even using it I still don't know how to do...
The main I use at the moment is :
int main( int argc, char *argv[ ], char *envp[ ]
found in a tutorial, it works for opening an opengl window but not for what i want as described lately.

jide
09-23-2006, 07:21 AM
If I understood correctly, you arguments to the simulation HAVE TO be treated inside argv. AFAIK I don't know extra new exotic parameters to add to main.

For the rest, can you be more precise ? In fact I don't really understand.

repie
09-23-2006, 07:38 AM
I'm sorry. I'm c++ beginner and my english isn't very good.
Actualy I want to make a .exe which first opens a shell, in it i'll put some parameters ( cin >> ).In the main i need to use some class methods dealing with the parameters.
Then an opengl window appears. Drawing what is in some privates of the class.
But I think I just managed to do this.
In the tutorial in foud, you're told to create a windows application project. I tried to create a project shell application (by the way i use dev-cpp), and it seems to work. I know have a shell and then an opengl window. I'm not sure at the moment, but thanks anyway. I'll ask again if that way isn't ok.

repie
09-23-2006, 07:47 AM
Hum actualy it doesn't seem to work.
There is the file, maybe it will be clearer.
This works, but if i use cubic cube; and cubic cube.saisir(); , the .exe fail (but compilation is still ok)


#include <cstdlib>
#include <iostream>
#include <gl/glut.h>
#include <cubic.h>
using namespace std;

int WindowName;

void Reshape(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(
45,
float(width)/float(height),
0.1,
100
);
glMatrixMode(GL_MODELVIEW);
}

void Draw()
{
glClear
(
GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT
);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,-10,0,0,0,0,1,0);
glBegin(GL_TRIANGLES);
glVertex2i(0,1);
glVertex2i(-1,0);
glVertex2i(1,0);

glEnd();
glutSwapBuffers();

glutPostRedisplay();
}

int main(int argc, char *argv[])
{
//cubic cube;
//cubic cube.saisir();

system("PAUSE");

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640,480);
WindowName = glutCreateWindow("OpenGL Window");


glutReshapeFunc(Reshape);
glutDisplayFunc(Draw);
//InitGL();

glutMainLoop();

return EXIT_SUCCESS;
}

jide
09-23-2006, 08:23 AM
Try to debug your program, it looks more like an error from within your class. This kind of code is expected to work.

repie
09-23-2006, 08:41 AM
Yes as shown it works, but when cubic cube; and
cube.saisir(); are on, the program fails, even if i debug. The class is ok, i tried it in another program without opengl.

repie
09-23-2006, 11:52 AM
You were right jide, it seems like there were too much private in the class, thanks a lot.
The problem now (not directly related to the topic), is I don't know how to put some class data (from methods) in the drawing function.
For example in order to draw, I'd like to put 'Dx' as a coordinate for a vertex, and I get it thanks to the method 'cube.getDx' .
But it looks like class methods are not recognized in Draw() (they are in the main now),
and I don't think the function allows parameters.
Any idea ?

Thanks for answers.

jide
09-23-2006, 12:58 PM
What you actually need is to learn about what programmation is, about your programming language and surely other things (maths...). This will definately help you A LOT.

Unfortunately this forum is not dedicated to that. If I don't tell you that, others will.
There are many sites that might help you. Or best, buy a book. Have a look at Amazon for that (or Eyrolles as it seems you're french).

But for your conveniencies, until you have your books, here is a hint:


cubic cube;should be declared global and before any other functions.

repie
09-24-2006, 01:27 AM
Ok sorry, thanks anyway.