PDA

View Full Version : (Me=Beginner) Have a look on DrawingCode please.



B_old
10-13-2002, 06:12 AM
Hey.
I am pretty new to OpenGL and my question is probably not very smart but the few things I learn about OpenGL I want to learn right, thats why I am asking.
Have a look please and thanks for your time.

I was lookin at a Nehe-tutorial about Printing text on the screen from a *.TGA.
I was struggling to get it done in the same scene as my excisting 3D-quad but I finally came up with this...
(It prints text and draws 3D-objects.)




//Inside my Drawingfunction, called every
//frame
glViewport(0,0, ScreenWidth, ScreenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, ScreenWidth,ScreenHeight,0.0f,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);


//Print
glPrint(50,16,1,"Some Text");

//Reset all the stuff
glViewport(0,0, ScreenWidth, ScreenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)ScreenWidth/(GLfloat)ScreenHeight,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Draw whatever 3D-Opbejcts.


I don't know anything about those Matrix-settings as I basically put together chunks of code, ripped from some tutorials.
It works, I am not so sure though if it is (even relatively) fast way of drawing, with all those strange calls.
What do you think?
Advice is very appreciated.
Thanks for your time.

[This message has been edited by B_old (edited 10-14-2002).]

nexusone
10-13-2002, 11:32 AM
I don't see any real problems in the code..


Originally posted by B_old:
Hey.
I am pretty new to OpenGL and my question is probably not very smart but the few things I learn about OpenGL I want to learn right, thats why I am asking.
Have a look please and thanks for your time.

I was lookin at a Nehe-tutorial about Printing text on the screen from a *.TGA.
I was struggling to get it done in the same scene as my excisting 3D-quad but I finally came up with this...
(It prints text and draws 3D-objects.)




//Inside my Drawingfunction, called every
//frame
glViewport(0,0, ScreenWidth, ScreenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, ScreenWidth,ScreenHeight,0.0f,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);


//Print
glPrint(50,16,1,"Some Text");

//Reset all the stuff
glViewport(0,0, ScreenWidth, ScreenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)ScreenWidth/(GLfloat)ScreenHeight,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Draw whatever 3D-Opbejcts.


I don't know anything about those Matrix-settings as I basically put together chunks of code, ripped from some tutorials.
It works, I am not so sure though if it is (even relatively) fast way of drawing, with all those strange calls.
What do you think?
Advice is very appreciated.
Thanks for your time.

[This message has been edited by B_old (edited 10-13-2002).]

[This message has been edited by B_old (edited 10-13-2002).]

[This message has been edited by B_old (edited 10-13-2002).]

[This message has been edited by B_old (edited 10-13-2002).]

B_old
10-14-2002, 05:48 AM
Hmm ok.
So those calls are not very expensive then?
Thanks for the reply

nexusone
10-14-2002, 06:03 AM
Only if you make the calls over sea's, then the charges can add up.....
http://www.opengl.org/discussion_boards/ubb/smile.gif



Originally posted by B_old:
Hmm ok.
So those calls are not very expensive then?
Thanks for the reply

B_old
10-14-2002, 11:11 AM
Ummmm. Over sea's?
*worried*
If I am printing something to the screen they are called every frame.
Is that over sea's?

EDIT:
OH DAMNIT!!!!
My english is not perfect and I am tired.
You got me... for about 1 minute or so.

EDIT 2:
You said no REAL problems...
*worried again*
Some minor then?

[This message has been edited by B_old (edited 10-14-2002).]

nexusone
10-14-2002, 11:59 AM
I did not want to be over picky about your code:

First you do have to re-draw the complete scene every time something on it changes.
When you get to drawing lots of objects, there are tricks and ways to improve the speed. Also you can just not redraw the screen unless something has moved or changed.

Things in code that could be changed:

glViewport... most times only called by windows when the user re-sizes the windows.
I put it in the glutReshapeFunc, which is only called by windows.
You have called it twice, it is redundent to call it a second time.

View port is the size of the drawing area to render to, does not have to be the same size as your perspective or ortho view.
If you are working on a 2D type game, having the view port and ortho the same can be inportant.

In your draw_routine you could add another glloadIdentity after the glMatrixMode(GL_MODELVIEW), which is called after the glOrtho call



Originally posted by B_old:
Ummmm. Over sea's?
*worried*
If I am printing something to the screen they are called every frame.
Is that over sea's?

EDIT:
OH DAMNIT!!!!
My english is not perfect and I am tired.
You got me... for about 1 minute or so.

EDIT 2:
You said no REAL problems...
*worried again*
Some minor then?

[This message has been edited by B_old (edited 10-14-2002).]



[This message has been edited by nexusone (edited 10-14-2002).]

B_old
10-15-2002, 05:52 AM
OK Thanks.
I kicked both the viewport calls.
I have a Resize-function myself actually, so.


[QUOTE]Originally posted by nexusone:
[B]I did not want to be over picky about your code:

First you do have to re-draw the complete scene every time something on it changes.
When you get to drawing lots of objects, there are tricks and ways to improve the speed. Also you can just not redraw the screen unless something has moved or changed.

Things in code that could be changed:

glViewport... most times only called by windows when the user re-sizes the windows.
I put it in the glutReshapeFunc, which is only called by windows.
You have called it twice, it is redundent to call it a second time.

View port is the size of the drawing area to render to, does not have to be the same size as your perspective or ortho view.
If you are working on a 2D type game, having the view port and ortho the same can be inportant.

In your draw_routine you could add another glloadIdentity after the glMatrixMode(GL_MODELVIEW), which is called after the glOrtho call

rosentzp
10-16-2002, 01:48 AM
hi

my english isn't very well too, but let's get to the point...
if you want to learn OpenGL, you have to learn fundamentals first - like 3D object modeling, matrix stacks, viewing and modeling transformations, if you learn this things well, then you will be prepared for complex issues like TGA loading(TGA loading is not exactly OpenGL issue, most like Win32 or even C Run-Time)

i recommend OpenGL Red Book, although this book seems to be for advanced programmers, and it is, but if you have Open GL Super Bible and...NeHe Tutorials and if you are consistent in your work, the results will be nice...

B_old
10-16-2002, 09:22 AM
Hello.
OK.
My code is based on NeHe's tutorial so far.
I have a *.pdf copy of the (free) RedBook (OpenGL 1.1) but I cannot print it on paper which would be very good. I'm considering to purchase one when OL 2 is released, though.
Can I get the SuperBible for free?

Did I mention that I am messing around with *.TGA's? I actually have a question about NeHe's way of doing it which I might ask here somewhere soon.

I am pobably formulating a question about displaying the CameraPitch right when I have finished this text. I would appreciate if you had a look on it.
Hope to see you and thanks for the help so far!

[This message has been edited by B_old (edited 10-16-2002).]