Announcement

Collapse
No announcement yet.

OpenGL tips

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenGL tips

    Compiling:
    To make SDL+GL code compile under Dev-C++, use the following project options:
    Compiler Options:
    Code:
    -I"\SDL" -Dmain=SDL_main
    Linker Options:
    Code:
    -lmingw32 -lSDLmain -lSDL -liberty -lopengl32 -lglu32
    If the code is advertised as "SDL/Linux" then it wont compile, it will bring up some weird error. You can either #include "windows.h" *before* including the GL headers, or you can do it how OpenSceneGraph does it, I'll attach the GL header to this post, you should be able to include this instead of "GL/GL.h" and it will do all the vodoo required to have GL.h included and working on all platforms

    Note also that under Linux, a SDL app will compile with a main defined as either
    int main(void) or int main(int argc, char **argv)
    However, under windows, main MUST be
    int main(int argc, char **argv)

    Tutorials:
    The two best resources are the NeHe OpenGL tutorials at www.gamdev.net and the OpenGL tutorials at www.gametutorials.com
    NeHe
    Gametutorials

    Note that you WILL get compile errors for the SDL code for these tutorials, however 95% of the time the only required modifications will be the two things I pointed out above.
    Last edited by Blake; December 19, 2002, 19:12.

  • #2
    hehe, I really should attach the darn file.

    Zipped so the board will accept it.

    Note the header is distribued under the GNU LGPL, meaning you can do pretty much anything you want with it except claim you wrote it
    Attached Files

    Comment


    • #3
      I'm looking a way to convert a SDL_Surface into an OpenGL texture: this will allow to use .PNG file format. Is it possible? Thank you for help.
      Aslo the gods are impotent against men's stupidity --Frederich Shiller
      In my vocabulary the word "Impossible" doesn't exist --Napoleon
      Stella Polaris Development Team -> Senior Code Writer (pro tempore) & Designer

      Comment


      • #4
        Why do you need it at all?
        SDL in conjunction with OpenGL is used not for graphics
        but for program initialization, threads, timers etc.

        Comment


        • #5
          Well, there are two ways:
          Get an image loader designed to load OpenGL textures. (this really does seem like the better way...)

          Take a SDL_Surface, and have some code to turn it into an OpenGL texture (this involves flipping the image, at the minimum). To find out how to do this, try looking at some of the tutorials - chances are the SDL versions will do something simialler.

          Comment


          • #6

            Comment


            • #7
              File Format Collection

              Comment


              • #8
                2 DJ - Was it a joke?
                I think that it's not yet decided what graphic libraries we will use. SDL+OpenGL are too low-level. And if we use something like OSG then there could be image loaders already.

                Comment


                • #9
                  I've found the code at GameDev, and I've modified it to load .PNG/.JPEG files.... Thanks for the help!
                  Aslo the gods are impotent against men's stupidity --Frederich Shiller
                  In my vocabulary the word "Impossible" doesn't exist --Napoleon
                  Stella Polaris Development Team -> Senior Code Writer (pro tempore) & Designer

                  Comment


                  • #10
                    Originally posted by Kurilka
                    2 DJ - Was it a joke?
                    I think that it's not yet decided what graphic libraries we will use. SDL+OpenGL are too low-level. And if we use something like OSG then there could be image loaders already.
                    No, it wasn't a joke. I've found that site very useful for figuring out loading .3ds models, .X models and jpeg files for Quake3 BSP levels, i just thought it could be helpful in helping you guys figure out loading PNG files.

                    Comment


                    • #11
                      ehm... DJ... I have the code to load .PNG file (SDL_image.h)
                      My problem is to discover how to handle a texture once opened...
                      There are no books on the arguments and tutorials I've found won't explain how-commands-work...
                      SDL is not exactly easy to learn... and OpenGL is less clear!
                      I suggest to reduce coders craziness to attach part of code to implement simple things like 2D texture loading/showing...
                      In the meanwhile I'll learn as much as I can from GameDev tutorials...
                      Aslo the gods are impotent against men's stupidity --Frederich Shiller
                      In my vocabulary the word "Impossible" doesn't exist --Napoleon
                      Stella Polaris Development Team -> Senior Code Writer (pro tempore) & Designer

                      Comment


                      • #12
                        Ok, well I'm not sure how SDL does there stuff, but if you have a texture loaded then all you should have to do is bind it.

                        glBindTexture(GL_TEXTURE_2D,(unsigned int)texID)

                        note that the second argument is a pointer, so if you don't have a pointer variable just assign the reference '&' memory address of that variable.

                        Also, if you haven't done this in your initialization do this before binding the texture

                        glEnable(GL_TEXTURE_2D);

                        This will allow for you to bind the textures, when you want to stop binding a certain texture use:

                        glDisable(GL_TEXTURE_2D);

                        One more thing, all texture must have attributes (size) of powers of 2.
                        Last edited by DJ; December 21, 2002, 12:57.

                        Comment


                        • #13
                          Ok, that was just the beginning basics, I'm posting this in a new post hoping this can clear what's really needed.

                          When you get a texture you should have read or extracted the bytes for it somehow and stored it in your byte pointer: unsigned char* imageData;

                          Ok, so now that you have that, through your library you can set it up for use in your OpenGL program like this:

                          Code:
                          
                          glGenTextures(1,&texID);
                          plBindTexture(GL_TEXTURE_2D,texID);
                          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
                          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
                          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)minFilter);
                          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint)maxFilter);
                          glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                          int mode = GL_RGB;
                          if(ci.depth==4) mode = GL_RGBA;
                          gluBuild2DMipmaps(GL_TEXTURE_2D,mode ,ci.width,ci.height,mode ,GL_UNSIGNED_BYTE,ci.imageData);
                          for the minFilter and maxFilter variables you can use GL_LINEAR or GL_NEAREST... mix them up and use GL_LINEAR_MIPMAP_NEAREST, this is just to get the best results in rendering the texture. Now that this is done you can use glEnable(GL_TEXTURE_2D) and glBindTexture(GL_TEXTURE_2D,&texID) for your use in your program.
                          Last edited by DJ; December 21, 2002, 13:04.

                          Comment


                          • #14
                            2 Vultur:
                            there are excellent OpenGL tutorials from NeHe (http://nehe.gamedev.net), and samples for SDL (could be found on SDL website)

                            Comment


                            • #15
                              Mmm... DJ, are you sure GL_MODULATE is right stuff? You prefer bother your head with vertex colors, are't you? They're surely more easy to handle dynamicaly, but it seems to be excessive for this situation.
                              If you don't see my avatar, your monitor is incapable to display 128 bit colors.
                              Stella Polaris Development Team, ex-Graphics Manager

                              Comment

                              Working...
                              X