Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Drawing with OpenGL

  1. #1

    Drawing with OpenGL

    Hello, I have recently learned how to use the basic functions of OpenGL and I would like to know a few more things.

    1. I know how to draw triangles, quads, lines and polygons; is there a routine to draw circles, cylindres, spheres, cones, spirals ??

    2. What is the command to set the alpha value (I use glColor3f(...) for colour, is there may be one that lets you set the alpha as well?) ?

    3. I have learnt about Lists. What are their advantages and disadvantages?

    Thanks for the help

  2. #2

    Re: Drawing with OpenGL

    Quote Originally Posted by IlovePascal
    1. I know how to draw triangles, quads, lines and polygons; is there a routine to draw circles, cylindres, spheres, cones, spirals ??
    Yes, look up GLUT in google, specifically for delphi. Else you can check out the red book.

    2. What is the command to set the alpha value (I use glColor3f(...) for colour, is there may be one that lets you set the alpha as well?) ?
    Yes, glColor4f(); will handle colors for you with alpha transparency. The Redbook is a great tool for learning about openGL.

    3. I have learnt about Lists. What are their advantages and disadvantages?
    Sorry, but I'm not well versed in vertex buffers, render lists and such. If you mean a TList to contain objects, then that's different; you should be more specific in this case.

  3. #3

    Drawing with OpenGL

    3. I have learnt about Lists. What are their advantages and disadvantages?
    Display lists are designed to increase performance. They allow to store a set of openGL commands in a memory in a 'compiled' form and call it when needed. To give an analogy, the drawing commands between glBegin...glEnd are like a source code. Display list is like an executable.
    Each time you draw something with glBegin...glEnd OpenGL needs to 'compile' it and then execute, while display list when called is executed straight away. A big speed gain. (It is like compiling program each time you want to use it versus compiling it once and runnig it without any recompilation). But it means that display lists are good for static geometry. You can't change part of it without recompiling whole list. So if your geometry changes a lot display lists are not effecitve. Lastly not all openGL commands can be put into display list.

    To get more information check the redbook like Robert suggests.

  4. #4

    Drawing with OpenGL

    Cool, thank you guys! I have just spend a whole afternoon reading some parts of the 'Red book'... my eyes are sore! lol

    But real interesting!

    One more question at the moment:

    - Is there a way of knowing where a point in the 3D matrix is on the screen? For example, I draw a triangle with many rotations and translations, then I work out where its centre of mass is and I draw a point there. How can I find out where in the screen that point will be displayed?
    Would I really have to do all the complex calculations, or is there an easier way, like reading from the buffer or something?
    Also, can I check the colour of a particular pixel on the screen or on the buffer ?

    Cheers

  5. #5

    Drawing with OpenGL

    I think gluProject is the anwser to your first question.

    To check color of the pixel on the screen use glReadPixels function.

  6. #6

    Drawing with OpenGL

    ur the man :thumbup::thumbup::thumbup:

  7. #7

    Drawing with OpenGL

    Can you destroy/erase a List?

    Like if I want to make an object move around for a few seconds, is it worth making a list to draw it, use the list for a while then destroy the list when the animation ends?

  8. #8

    Drawing with OpenGL

    Can you destroy/erase a List?
    Yes. The lists are created and destroyed with calls to glGenLists and glDeleteLists. The contents of the list are specified by putting the drawing commands between glNewList..glEndList pair (glGenLists creates empty list). If the glNewList is called for a list which is not empty, its old contents are replaced with new one.
    Like if I want to make an object move around for a few seconds, is it worth making a list to draw it, use the list for a while then destroy the list when the animation ends?i
    Why would you want to destroy the list? You can use it to draw object, no matter if it moves or not.

  9. #9

    Drawing with OpenGL

    Hey, I read a whole bunch about the procedures/functions you mentioned, but when I tried using them, it didn't work!

    I have a few questions tht might help...

    -Why does this not work:
    Code:
    Procedure Matrix_to_Win;
    var model, proj, Winx,Winy,Winz : PGLdouble;
        Matrixx,Matrixy,Matrixz : real;
        view : PGLint;
    begin           
     {view := 0;
     model := GL_MODELVIEW;
     proj := GL_PROJECTION;}
     Winx := 0; Winy := 0; Winz := 0;
     Matrixx := 0; Matrixy := 0; Matrixz := 0; 
    
     glGetDoublev(GL_MODELVIEW_MATRIX, model);
     glGetDoublev(GL_PROJECTION_MATRIX, proj);
    
     glGetIntegerv(GL_VIEWPORT, view);
    
    
     gluProject(Matrixx, Matrixy, Matrixz,
                   model, proj, view,
                   Winx, Winy, Winz);
    end;
    I found that in an example they had on the internet, but it doesn't seem to work. Any clues?
    I tried commenting out all the gl lines but one to see where the problem was but they all bugged! lol

    -The gluProject 'returns' WinX, WinY and WinZ, right? bt those are the coordinates of the screen, right? then why a Z coordinate? :scratch:

    -Does it return coordinates outside the screen too?

    -If I want to use the Win coordinates, i'd like to make them integers, how do I do that?
    How to convert PGLdouble to LongInt?
    Double to longint?

    Cheers

  10. #10

    Drawing with OpenGL

    This procedure does not work because OpenGL functions do not allocate memory to store results. Although the specs says that glGetDoublev expects PGLDouble as a parameter (PGDouble - pointer to a double type) but actually it expects an array of doubles big enough to store the result of the query.

    Pascal versions of glu(Un)Projects expects specific data types which are defined in glu.pas.

    Here is a corrected version of your Matrix_to_win procedure
    Code:
    // objx,objy,objz - 3D location of a point 
    // screenX, screenY - will hold screen coordinates of (objx,objy,objz)
    procedure Matrix_To_Win(objx,objy,objz : gldouble;  var screenX : integer,  var screenY : integer);
    var
     model, proj : T16dArray;  //type defined in glu.pas
     view : TViewportArray;    //also defined in glu.pas
     winx,winy,winz : glDouble; 
    begin
     glGetDoublev(GL_PROJECTION, @proj);
     glGetDoublev(GL_MODELVIEW, @model);
     glGetIntegerv(GL_VIEWPORT,@view);
    
     gluProject(objx,objy,objz, proj, model, view, @winx, @winy, @winz);
     screenX := Round(winx);
     //since OpenGL treats lower left corner as a (0,0) winy must be
     //transformed to normal window coordinates with (0,0) at upper left
     //corner
     screenY := ScreenHeight - Round(winy);
    end;
    The z coordinate is a depth value. It is put into depth buffer and is used for depth sorting.

    I think that gluProject may return coordinates that are outside the screen.

    P. S. If you use FPC and gluProject crashes your application, look at this thread http://www.pascalgamedevelopment.com...pic.php?t=3636

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •