Announcement

Collapse
No announcement yet.

OpenGL Question.

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

  • OpenGL Question.

    I have downloaded and looked at every OpenGL example I can find
    but I have not come across any that demonstrate how to load and
    draw a 2d image to the screen. No rotations, no spining, no
    3d objects, just a simple 2d image.

    I am using PB 7.02

    Can anyone help me here? In DirectX 8 (Direct3d) (In VB) I load an
    image as a texture and then from it I draw to the buffer, then
    swap. I want to do the same thing with OpenGL (In PB).


    ------------------
    Talent is not something you learn, its something you refine.
    Talent is not something you learn, its something you refine.

  • #2
    I have managed to achive my desired results, but there is a
    function that it calls to gather the image data auxDIBImageLoad
    I tried and duplicate this function but to no avail. Does anyone
    have any information on this function?
    ------------------
    Talent is not something you learn, its something you refine.

    [This message has been edited by Jesse Ryan Baker (edited June 06, 2003).]
    Talent is not something you learn, its something you refine.

    Comment


    • #3
      OpenGL doesn't natively support 2D like older versions of
      DirectX with DirectDraw did. I haven't tried this before,
      but I think one solution would be to create a quad surface
      and map the texture to it with glBindTexture and the related
      calls. If I recall correctly, there is a way to set the
      perspective to a parallel projection. So basically, you
      might be able to make a 3D surface positioned in a way that
      covers the screen, then draw other little quad "bitmaps" ahead
      of it. With a parallel projection, this might look ok.

      Anyway, that's what I would try first if I were doing it.

      As far as auxDIBImageLoad goes, here is some sample code in PB:

      Code:
        DIM lpTexture(1) '2 textures
      
        ' We have 2 textures.
      
        glGenTextures 2, lpTexture(0)
      
        ' Load texture (first texture)
        lpImage = auxDIBImageLoad("first.bmp")
        glBindTexture %GL_TEXTURE_2D, lpTexture(0)
      
        ' Linear filtered texture
        glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR
        glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR
        glTexImage2D %GL_TEXTURE_2D, 0, 3, @lpImage.sizeX, @lpImage.sizeY, 0, %GL_RGB, %GL_UNSIGNED_BYTE, @[email protected]
      
        ' Load texture(second texture)
        lpImage = auxDIBImageLoad("ground.bmp")
        glBindTexture %GL_TEXTURE_2D, lpTexture(1)
        glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR
        glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR_MIPMAP_LINEAR
      
        'Enable textures.  I'm not if this is really necessary; it might be defaulted to this.
        glEnable %GL_TEXTURE_2D
      This is only done once in the program of course. During
      rendering you load the first texture like this:

      Code:
      glBindTexture %GL_TEXTURE_2D, lpTexture(0)
      And the second:
      Code:
      glBindTexture %GL_TEXTURE_2D, lpTexture(1)
      Hope that helps.

      ------------------
      Todd Wasson http://PerformanceSimulations.Com
      PowerBasic Racing Simulator:http://performancesimulations.com/scnshot4.htm

      [This message has been edited by Todd Wasson (edited June 06, 2003).]
      Todd Wasson
      http://PerformanceSimulations.Com
      PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

      Comment


      • #4
        Yeah I was able to do that after some research, what I am having
        having troubles with is tranparent images & or alphablended images.


        As far as auxDIBImageLoad goes, I was meaning a replacement
        function so I am not forced to use the DLL that function is in.
        I managed a replacement function so I am good on that end.
        ------------------
        Talent is not something you learn, its something you refine.

        [This message has been edited by Jesse Ryan Baker (edited June 06, 2003).]
        Talent is not something you learn, its something you refine.

        Comment


        • #5
          One way to simply show 2D graphics is to switch to ortho mode (I think the command is something like glOrtho). This will give you a set X Y dimension (like that used in 2D). The Z is still used, but is used more for "layers" than for depth.

          Whether you use ortho or not, it should be fairly simple to draw a flat 2D image:

          Code:
          glEnable GL_TEXTURE_2D
          glBindTexture GL_TEXTURE_2D, texID
          glPushMatrix
          glColor3f 1!, 1!, 1!
          glTranslatef x, y, 0!
          glBegin GL_QUADS
             glTexCoord2f 0!, 0!: glVertex3f -w, -h, 0!
             glTexCoord2f 1!, 0!: glVertex3f -w,  h, 0!
             glTexCoord2f 1!, 1!: glVertex3f  w,  h, 0!
             glTexCoord2f 0!, 1!: glVertex3f  w, -h, 0!
          glEnd
          glDisable GL_TEXTURE_2D
          glPopMatrix
          That *should* work. x, y is the location to draw the texture, w is the width of the texture and h is the height of the texture. (You will have to switch to ortho mode first if you want x, y, w, and h to be in pixels rather than screen units.)

          If you want to blend the texture, change glColor3f 1!, 1!, 1! to:

          Code:
          glEnable GL_BLEND
          glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
          glColor4f 1!, 1!, 1!, 0.5!
          where 0.5! is your alpha (blend) value. (Don't forget to turn off blending with glDisable GL_BLEND when done drawing!)

          Hope this helps!

          Thanks,
          Flick


          ------------------


          [This message has been edited by Bryan Flick (edited June 07, 2003).]

          Comment


          • #6
            I didnt want to alphablend the texture but thanks.
            I managed to use masks and create transparencies, but this doesnt
            suit my style of system, if anyone knows of a color key based
            method rather than masks it would help me alot. Because the
            masks are an exact copy of the image (a full 24bit copy) with
            the transparent area white and the solid area black, I saw no
            "feature" that allowed loading of this as a monochromatic image
            rather then a full blown texture. This result is a copy of every
            one of my textures being loaded into memory (as masks) thats
            double the memory useage, does anyone know if OpenGL nativly
            compresses these with a RLE method of some sort so the 24bit image
            of just black and white wont take the same memory as the other?

            Note that I know a color key method can be used manually by
            passing over your texture and changing all the ALPHA (or reserved)
            channel to 0 for transparent, 255 for solid (basically creating
            a mask INSIDE of the image) but when I draw the image, the
            transparent color is only like 15% transparent, the rest of the
            image is solid...

            This is hard, I am working without documentation, and without
            examples. (C++ docs and C++ examples are worse than no examples
            to me, so those dont count)

            sublevel6 (which hasnt been updated in years) provides the basics
            of 3d geometry, but doesnt really touch on the subjects I need
            to learn on, so I am kind of on my own here, I have never used
            PB for a graphics engine, and I have never used OpenGL and I have
            no examples or docs that are in a readable format for me. Im in
            the middle of the ocean on a raft without paddles. Im getting
            SOMEWHERE but its taking me days to do what should only take
            hours.

            Anyways, any "Color Key" method of transparency, or ways to draw
            NORMAL text to the screen, I dont want 3d rotating flashing color
            text, just regular text <IMG SRC="http://www.powerbasic.com/support/forums/smile.gif" ALT="smile"> (ill probably stumble upon the latter
            sooner or later, trial and err, trial and err, but the color key
            issue would be a huge help if someone could assist me in such)

            On a side note, If I draw my graphics at 0 (pixel) on the Y axis
            it "tweeks" them, if I draw it 1 pixel offset then it draws them
            perfect but I have a 1 pixel black line across the top of my
            screen....anyone know why?

            ------------------
            Talent is not something you learn, its something you refine.



            [This message has been edited by Jesse Ryan Baker (edited June 07, 2003).]
            Talent is not something you learn, its something you refine.

            Comment


            • #7
              Originally posted by Jesse Ryan Baker:
              Note that I know a color key method can be used manually by
              passing over your texture and changing all the ALPHA (or reserved)
              channel to 0 for transparent, 255 for solid (basically creating
              a mask INSIDE of the image) but when I draw the image, the
              transparent color is only like 15% transparent, the rest of the
              image is solid...
              That's probably the best way to do it. Load your textures as 32-bit textures instead of 24-bit textures... That way you could set the alpha channel for each pixel in the texture. Granted, it would be an extra 8 bytes for every pixel, but it wouldn't be as memory expensive as loading an entire duplicate texture with just black and white on it to create masks.

              Even if you loaded your textures as 24-bit, it shouldn't be hard to convert them to 32-bit. Then you can pick a pixel that should be transparent and scan through the texture, setting the alpha channel for that pixel to 0. All other alpha channel pixels should be set to 255 (for opaque).

              I'm not sure why it would show 15% transparent... It shouldn't show any pixel with an alpha channel of 0. What blending mode were you using?

              Flick


              ------------------




              [This message has been edited by Bryan Flick (edited June 07, 2003).]

              Comment


              • #8
                Ok I figured out my error, I wasnt reading up enough on the
                functions that the examples used, I went to the online MSDN and
                found some really good information (its in C++ but I managed to
                understand it and figured out that in one function when it was
                creating the texture, it was loading it as an internal format
                WITHOUT the alpha channel, although I had the alpha channel in
                the inital format, it was getting lost in the load.


                ------------------
                Talent is not something you learn, its something you refine.



                [This message has been edited by Jesse Ryan Baker (edited June 08, 2003).]
                Talent is not something you learn, its something you refine.

                Comment

                Working...
                X