Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 43

Thread: 2D using OpenGL

  1. #31

    2D using OpenGL

    So if you get it to work on XP it also works on 98?

  2. #32

    2D using OpenGL

    So far that's been the case.

    I've been developing mainly on a win98 machine and a bit on an xp machine.
    But now I'm purely going XP, so let's fully test this theory when my game is finished
    Huhuhu

  3. #33

    2D using OpenGL

    I came up with another problem.

    I know I can do blending with a mask layer and make parts of a polygon transparent.

    Now I want to do a "fade to nothingness" effect.
    This means I have a picture I show (partially transparent using a mask layer). I want the whole to become more and more transparent overall until it disappears because it's reached a maximum transparency.

    Example:

    Code:
            glEnable(GL_BLEND);
            glDisable(GL_DEPTH_TEST);
            glBlendFunc(GL_DST_COLOR,GL_ZERO);
            glBindTexture(GL_TEXTURE_2D,backmask[z]);
            glBegin(GL_QUADS);
              glTexCoord2f( 0.001, 0.99); glVertex3f( i*20-60.0001,-j*20+40.0001, -30.0);
              glTexCoord2f( 0.001, 0.01); glVertex3f( i*20-60.0001,-j*20+19.9999, -30.0);
              glTexCoord2f( 0.999, 0.01); glVertex3f( i*20-39.9999,-j*20+19.9999, -30.0);
              glTexCoord2f( 0.999, 0.99); glVertex3f( i*20-39.9999,-j*20+40.0001, -30.0);
            glEnd();
            glBlendFunc(GL_ONE,GL_ONE);
            glBindTexture(GL_TEXTURE_2D,backtex[z]);
            glBegin(GL_QUADS);
              glTexCoord2f( 0.001, 0.99); glVertex3f( i*20-60.0001,-j*20+40.0001, -30.0);
              glTexCoord2f( 0.001, 0.01); glVertex3f( i*20-60.0001,-j*20+19.9999, -30.0);
              glTexCoord2f( 0.999, 0.01); glVertex3f( i*20-39.9999,-j*20+19.9999, -30.0);
              glTexCoord2f( 0.999, 0.99); glVertex3f( i*20-39.9999,-j*20+40.0001, -30.0);
            glEnd();
            glEnable(GL_DEPTH_TEST);
            glDisable(GL_BLEND);
    I know there's something possible to make the whole more transparent, but how?
    Let's say I want to give it 25% visibility, which is 75% transparency.
    Huhuhu

  4. #34

    2D using OpenGL

    Look into:
    Code:
     glColor4ub(R,G,B,A);
    where rgba are byte values.
    In your case its probably glColor4ub(255,255,255,[0..255]);

  5. #35

    2D using OpenGL

    Traveller: after having your avatar roll its eyes at me thousands of times, I appreciate the change

    Smotsholle: I think you may be going about this the wrong way..

    First, you should use alpha channels, they make your life a lot easier. Creating the art will be a *little* trickier since you have to use TGA or PNG images.

    There is a TGA file loader here which loads a TGA and it's Alpha channel:
    http://www.sulaco.co.za/opengl_proje...ure_loader.htm
    With simple instructions.

    You can download a TGA picture to test out here:
    http://www.sulaco.co.za/nitrogen/junk/map.tga

    Ok, once you have a texture with an alpha channel, this is how you draw it with a 'fade-to-nothing' effect:

    Code:
      glBindTexture(GL_TEXTURE_2D, MyTexture);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //this does the alpha blending.
      
      glcolor4f(1,1,1, FadeAmount); //This does the fading, set FadeAmount to 0 for total transparency, and 1 for full opacity.
    
      glBegin(GL_QUADS);
        glTexCoord2f(0,1); glVertex2f(X-Size, Y-Size);
        glTexCoord2f(1,1); glVertex2f(X+Size, Y-Size);
        glTexCoord2f(1,0); glVertex2f(X+Size, Y+Size);
        glTexCoord2f(0,0); glVertex2f(X-Size, Y+Size);
      glEnd;
    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  6. #36

    2D using OpenGL

    Quote Originally Posted by Smotsholle
    Another Thing I found out on the internet was the fact that I can place a maximum of 8 lights on the screen GL_Light0 to GL_Light7, is this true? and if so, I there a way to work around that?
    There's actually a way, using multipass rendering, supports virtually unlimited number of lights :

    http://www.delphi3d.net/download/lightaccum.zip
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  7. #37

    2D using OpenGL

    I've changed the rules of the game a bit so I only need one light.

    About the alpha layer. I managed to get it working using the first rule.
    But I might be able to use the second advice for future projects.
    I'll certainly keep the extra lighting tip in store too for future projects.
    Huhuhu

  8. #38

    2D using OpenGL

    Hello everyone, I'm back again after a long time.

    Had a 6 week vacation and I've been gone so much I haven't been online in that time.

    Now I'm back working on this project again.
    Glad to say the game itself is just about bug-free.

    I've found 6 bugs now and I'm able to fix two of them.

    The other 4 bugs are related (Same bug occurs in different parts of the game).

    I've copied the game on a central network disk. This means everyone on this network plays the same game.
    I've allowed 6 children to play this game simultaneously and starting the game didn't seem to be too much of a problem. Just encountered a slow-down because all 6 of them were loading the same images(BMP files) from a subdirectory in the game.
    The real bug is file reading/writing:
    There are some binary files (saved records) which store the important data (levels, highscore lists, accounts, etc....).
    As they played the game it could suddenly begin to crash when they tried to read from those files or write to them (not certain about the writing though).

    When creating this game I assumed that the time between opening and closing the file would be a fraction of a second. I thought this would make it nearly impossible to get any kind of bug there. Obviously I was mistaken.

    The children tried it stand alone, so no delphi error, just a generic error with the "Send" and "Don't send" button (you know what I mean).


    I've thought of a sollution myself, but I don't know this will work or how to implement it.
    I'll show you a file read function first to explain:

    Code:
    function LoadFromVrgFile(filename:string):TMySaveRecord;
    var myFile : File of TMySaveRecord;
        tv: TMySaveRecord;
    begin
        AssignFile(myFile, filename);
        Reset(myFile);
        Read(myFile, tv);
        result := tv;
        CloseFile(MyFile);
    end;
    I thought of catching the read/write error, should it occur.
    If it does, just try again (with a max of 20 times, should be enough).
    If it goes wrong more than 20 times I'll assume the file itself is bad.

    Is this the right way to go about things or not?
    If so, is this the right way to implement this?

    Code:
    function LoadFromVrgFile(filename:string):TMySaveRecord;
    var myFile : File of TMySaveRecord;
        tv: TMySaveRecord;
        i:integer;
    begin
        AssignFile(myFile, filename);
        i := 0;
        Error := True;
        while &#40;i < 20&#41; AND &#40;Error&#41; do
        begin
          Error &#58;= False;
          Reset&#40;myFile&#41;;
          &#123;$I-&#125;
          Read&#40;myFile, tv&#41;;
          &#123;$I+&#125;
          If IOResult <> 0 then
          begin
            Error &#58;= True;
            inc&#40;i&#41;;
          end
          else
            result &#58;= tv;
          CloseFile&#40;MyFile&#41;;
        end;
    end;
    Made this code from the top of my head, would this work?
    Huhuhu

  9. #39

    2D using OpenGL

    1. Hmmm... Shouldn't it generate an error on Reset first...?

    2. Add some Sleep()/Wait() between retries...?

    3. Would FileMode work in this case, to make file access exclusive?

    4. Use TFileStream in pair with Try/Except?..

  10. #40

    2D using OpenGL

    1. I'm not sure where the error occurs. I've tested this with the compiled EXE only.
    2. I've managed to put the loop on hold for a while due to the 3rd point you mentioned.
    3. I'm trying the file mode thing right now. Gonna test it soon. I'll let you know how it turns out.
    4. Don't really understand this one. Do you have a piece of example code?
    Huhuhu

Page 4 of 5 FirstFirst ... 2345 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
  •