Qbasicnews.com

Full Version: Help with "translating" from C to FB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I found this tutorial about a particle engine on NeHe, and I've tried to get it to work with FB, but there's some things that I don't know how to "translate" to FB...

Here we go:
Code:
int LoadGLTextures()                        // Load Bitmaps And Convert To Textures
{
    int Status=FALSE;                    // Status Indicator

    AUX_RGBImageRec *TextureImage[1];            // Create Storage Space For The Texture

    memset(TextureImage,0,sizeof(void *)*1);        // Set The Pointer To NULL
    if (TextureImage[0]=LoadBMP("Data/Particle.bmp"))    // Load Particle Texture
    {
        Status=TRUE;                    // Set The Status To TRUE
        glGenTextures(1, &texture[0]);            // Create One Textures

        glBindTexture(GL_TEXTURE_2D, texture[0]);
        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, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    }

    if (TextureImage[0])                    // If Texture Exists
    {
        if (TextureImage[0]->data)            // If Texture Image Exists
        {
            free(TextureImage[0]->data);        // Free The Texture Image Memory
        }
        free(TextureImage[0]);                // Free The Image Structure
    }
    return Status;                        // Return The Status
}

and...

Code:
        particle[loop].r=colors[loop*(12/MAX_PARTICLES)][0];        // Select Red Rainbow Color
        particle[loop].g=colors[loop*(12/MAX_PARTICLES)][1];        // Select Red Rainbow Color
        particle[loop].b=colors[loop*(12/MAX_PARTICLES)][2];        // Select Red Rainbow Color

Code:
        particle[loop].fade=float(rand()%100)/1000.0f+0.003f;        // Random Fade Speed

I guess the last one is something similiar to:
Code:
particle(i).fade = Int(Rnd * 100) / 1000 + 0.003
Right?

Particle Engine on NeHe http://nehe.gamedev.net/data/lessons/les...?lesson=19
Code:
MAX_TEXTURES = 19
dim shared texture(MAX_TEXTURES) as integer

function LoadGLTextures()

   declare img_width as integer, img_height as integer, img_size as integer
   img_width = 64
   img_height = 64
   img_size = img_width * img_height + 4
   dim TextureImage(img_size) as integer
   bload "data/particle.bmp", @TextureImage(0)
   if TextureImage(0) = 0 or TextureImage(1) = 0 then 'error
      LoadGLTextures = 0
      exit function
   end if

   glGenTextures 1, @texture(0)
   glBindTexture GL_TEXTURE_2D, texture(0)
   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, img_width, img_height, 0, GL_RGB, GL_UNSIGNED_BYTE, @TextureImage(0)
   'image array should be automatically deallocated
   LoadGLTextures = -1

end function

and

Code:
'colors is a 2d array of integers... I don't know the dimensions used in the program you referenced
particle(i).r=colors(i*(12/MAX_PARTICLES),0)
particle(i).g=colors(i*(12/MAX_PARTICLES),1)
particle(i).b=colors(i*(12/MAX_PARTICLES),2)

and

Code:
'MAX_RND_VALUE is determined usually near the beginning of a C program, using a function whose name I can't currently remember
'The % operator is equivalent to QB's MOD command, not multiplication.
particle(i).fade=((rnd * MAX_RND_VALUE) mod 100)/1000+0.003

I haven't tested any of this, so it might contain errors. But I hope not Smile Good luck.
Bummer I can't test it until I get home.... work = :barf: