Very Newbye Opengl Question.

Apoc

Regular
I'll start saying that I'm trying to learn on my own and I've just started with opengl (no directx knowledge) so don't laugh. I'm making a program for college, and I'm stuck. I have to make a 400x400 window, and a right button menu that pop 5 options: 1) function1; 2) Function2; 3)Sierpinki Triangle; 4) A dino draw with polylines and 5) Clear Screen.

My menu works, but it doesn't behave as expected.

BTW, I can't understand all the viewport scaling fuzz, as my book just plain SUCKS. Can you make a little description of how it works.


Here is my cpp (is a Visual C++ one) and the .dat file needed to draw the dino. Link

Some help will be welcomed.

Thanks in advance.
 
You should get the opengl red book... it explains things very well although you can be a bit overwhelmed at first (the whole vertex array thingy in the start doesn't make sense for someone who uses the book as an incremental learning tool).

It's online somewhere on the net.

What exactly are you having trouble with?
 
t0y said:
You should get the opengl red book... it explains things very well although you can be a bit overwhelmed at first (the whole vertex array thingy in the start doesn't make sense for someone who uses the book as an incremental learning tool).

It's online somewhere on the net.

What exactly are you having trouble with?

I have my menu working, and it draws the first function selected, but from this point the program stops working (well, the menu works, but does nothing). I know it has to be something very simple, but I can't figure what.

My other problem is that my functions don't scale to the viewport size (they appear cropped). I know it has to do with glviewport(), but this book is very bad and doesn't explain it well.

I'll try to grab the red book btw.


There are parts of the code that are commented, don't pay attention to these, they were things I was trying to make the program work.
 
Be warned the Red book is an excellent reference, but it's not a GL tutorial by any stretch.
 
I won't do it for you, but I can give you some hints:
  1. All drawing code should be in myDisplay(), or in functions called by this function;
  2. glClear() should always be called first and only once in myDisplay(). In the case of clearing the screen, you simply don't draw anything after it.
  3. The menu function should only update some global variable that controls which drawing function gets called in myDisplay.
  4. You should redraw the screen in the menu function (I called myDisplay() directly, but I don't know if that's the proper way in glut).
  5. The glViewport function is used to define how much of the window will be used for rendering. Your code looks fine but you're calling it in the wrong place. Both setwindow() and setviewport should be in a resize callback function (look it up) and not in drawing code.
  6. To avoid cropping, you need to scale the viewport to match the size of what you want to draw or, in alternative, you can scale what you draw. The glOrtho2D call in my init(), for example, says that whatever the window size and viewport, the gl coordinates will be from 0 to 400 both horizontally and vertically.
Note that most of the stuff I'm saying is from memory!
You should also check NeHe's site. Most of the tutorials have glut ports, I guess.
 
ERP said:
Be warned the Red book is an excellent reference, but it's not a GL tutorial by any stretch.

I supossed that. I'm going to grab the OpenGL SuperBible and the Red Book. I think they will do.
 
t0y said:
I won't do it for you, but I can give you some hints:
  1. All drawing code should be in myDisplay(), or in functions called by this function;
  2. glClear() should always be called first and only once in myDisplay(). In the case of clearing the screen, you simply don't draw anything after it.
  3. The menu function should only update some global variable that controls which drawing function gets called in myDisplay.
  4. You should redraw the screen in the menu function (I called myDisplay() directly, but I don't know if that's the proper way in glut).
  5. The glViewport function is used to define how much of the window will be used for rendering. Your code looks fine but you're calling it in the wrong place. Both setwindow() and setviewport should be in a resize callback function (look it up) and not in drawing code.
  6. To avoid cropping, you need to scale the viewport to match the size of what you want to draw or, in alternative, you can scale what you draw. The glOrtho2D call in my init(), for example, says that whatever the window size and viewport, the gl coordinates will be from 0 to 400 both horizontally and vertically.
Note that most of the stuff I'm saying is from memory!
You should also check NeHe's site. Most of the tutorials have glut ports, I guess.

I'm happy you didn't do it for me. At last I fixed it, and tuned the code a bit. It works perfect now, the only thing I have not implemented is the resize function (will do tomorrow, is late here).

Thanks, you helped more than what you think.
 
Back
Top