.dll to .a ?

Started by
11 comments, last by Frenzy123 15 years, 3 months ago
OK another question for you guys. Im trying to use freeimage to load a simple texture into my Linux openGL based project. The only thing is the library that comes with this is in .dll format. There is a read me file that mentions something about using a dos shell and some commands to convert it .... i didnt even know you could access dos on Linux ? Is there an easier way or a program that can convert this into the correct format (i assume .a or .so).
Advertisement
Download the source code from here, extract the archive, open a terminal, move to the directory and execute 'make'. It should create both static library "libfreeimage.a" and the shared library "libfreeimage-3.11.0.so". To install the library run 'make install' (as root if needed).
Just as a side note, shared libraries have usually the extension .so under linux and not .dll .

If you are using Ubuntu, you can install freeimage using Synaptic (System->Administration->Synaptic Package Manager).
.dll is the runtime code they wrote for you. The .a is the interface for the DLL.

.Lib = .a on linux

It will come with both if you have downloaded the correct files.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Ah? DLL are Windows Dynamic Linking Libraries, they don't work on other OSes, specially Linux. You're using the wrong version of the library, there should be a source version you can compile, or a linux prebuild package.
Really big help guys im new to Linux and i forgot to make install which was my main problem. I got FreeImage to compile and i have included it and used it within my program.

Now the next problem :S. Im using Fedora Core 7 on my PS3 to program a simple particle engine using openGL. i require textured particles hence FreeImage.

Here is the code i use for the texture load. It is taken from the openGL example from FreeImage but i have chanegd it a little to make it run in C.

int LoadTexture(const char* filename, const unsigned int texID, GLenum image_format, GLint internal_format, GLint level, GLint border)
{
//image format
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
//pointer to the image, once loaded
FIBITMAP *dib(0);
//pointer to the image data
BYTE* bits(0);
//image width and height
unsigned int width(0), height(0);
//OpenGL's image ID to map to


//check the file signature and deduce its format
fif = FreeImage_GetFileType(filename, 0);
//if still unknown, try to guess the file format from the file extension
if(fif == FIF_UNKNOWN)
fif = FreeImage_GetFIFFromFilename(filename);
//if still unkown, return failure
if(fif == FIF_UNKNOWN)
return 0;

//check that the plugin has reading capabilities and load the file
if(FreeImage_FIFSupportsReading(fif))
dib = FreeImage_Load(fif, filename);
//if the image failed to load, return failure
if(!dib)
return 0;

//retrieve the image data
bits = FreeImage_GetBits(dib);
//get the image width and height
width = FreeImage_GetWidth(dib);
height = FreeImage_GetHeight(dib);
//if this somehow one of these failed (they shouldn't), return failure
if((bits == 0) || (width == 0) || (height == 0))
return 0;

//if this texture ID is in use, unload the current texture
//if(m_texID.find(texID) != m_texID.end())
// glDeleteTextures(1, &(m_texID[texID]));

//generate an OpenGL texture ID for this texture
glGenTextures(1, &gl_texID);
//store the texture ID mapping
//m_texID[texID] = gl_texID;
//bind to the new texture ID
glBindTexture(GL_TEXTURE_2D, gl_texID);
//store the texture data for OpenGL use
glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height,
border, image_format, GL_UNSIGNED_BYTE, bits);

//Free FreeImage's copy of the data
FreeImage_Unload(dib);

//return success
return 1;
}

As far as i can tell this is succeful as it returns 1 when i enter a correct texture file and 0 when i enter a file name that doesnt exist.

I use this to bind the texture.

void BindTexture()
{
glBindTexture(GL_TEXTURE_2D,gl_texID );

}

and here is my render function for the particles and where the previous function is called.

void PSRender(ParticleSystem* ps,bool repeat)
{BindTexture(1);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

for(int i = 0;i<ps->NumberofParticles;i++)
{
if(ps->P.Activated == true)
{
if(ps->P.Age < ps->P.LifeSpan)
{
glEnable(GL_TEXTURE_2D);

glPushMatrix();

glTranslatef(ps->P.Posx, ps->P.Posy, ps->P.Posz);
glRotatef(ps->P.Degree,0,1,0);


glBegin(GL_QUADS);

glTexCoord2f(0.0f,0.0f);glVertex3f(-ps->P.Sizex, ps->P.Sizey, ps->P.Sizez);
glTexCoord2f(0.0f,1.0f);glVertex3f(ps->P.Sizex, ps->P.Sizey, ps->P.Sizez);
glTexCoord2f(1.0f,1.0f);glVertex3f(ps->P.Sizex, -ps->P.Sizey, ps->P.Sizez);
glTexCoord2f(1.0f,0.0f);glVertex3f(-ps->P.Sizex, -ps->P.Sizey, ps->P.Sizez);

glEnd();

glPopMatrix();

glFlush();

}
}

As far as i know that should bind the texture to each particle which atm is simple a square.But the aprticles are showing without a texture. I have tried several different file formats with differnt bit depth.

I have used openGL alot so im thinking i must have missed something out that im just not seeing. I appreciate that there is alot of code there guys. Any help would be appreciated.


Thanks

void BindTexture(){    glBindTexture(GL_TEXTURE_2D,gl_texID );}...BindTexture(1); 

I guess gl_texID is a global variable, so what is this parameter? Without a complete program, there can be all sorts of initialization problems; you don't even give the call to LoadTexture.
Quote:Here is the code i use for the texture load. It is taken from the openGL example from FreeImage but i have chanegd it a little to make it run in C.

Do you have a working test program, such as the mentioned example, that you can modify?
Separating file format issues (which would appear if you adapt working sample code to your images) from initialization and rendering issues (which are hopefully confined to your particle engine) would be a good step forward.

Omae Wa Mou Shindeiru

My particle engine runs and works well. I cannot get an example that came with freeimage working because, the openGL example that comes with program is for windows and coded in C++.The Linux version is not for openGL... i would need an example that was both in openGL and for Linux.

I am making the call to load texture in my main function and tex id is global, its an unsigned int.

Here is the full program which i didnt initially link due to its length and mostly irrelevant to my problem. Thankyou for any further help.

#include <GL/glut.h>
#include "stdlib.h"
#include <libvector.h>
#include "FreeImage.h"

#define HEIGHT 300
#define WIDTH 300

GLuint gl_texID;

int LoadTexture(const char* filename, const unsigned int texID, GLenum image_format, GLint internal_format, GLint level, GLint border)
{
//image format
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
//pointer to the image, once loaded
FIBITMAP *dib(0);
//pointer to the image data
BYTE* bits(0);
//image width and height
unsigned int width(0), height(0);
//OpenGL's image ID to map to


//check the file signature and deduce its format
fif = FreeImage_GetFileType(filename, 0);
//if still unknown, try to guess the file format from the file extension
if(fif == FIF_UNKNOWN)
fif = FreeImage_GetFIFFromFilename(filename);
//if still unkown, return failure
if(fif == FIF_UNKNOWN)
return 0;

//check that the plugin has reading capabilities and load the file
if(FreeImage_FIFSupportsReading(fif))
dib = FreeImage_Load(fif, filename);
//if the image failed to load, return failure
if(!dib)
return 0;

//retrieve the image data
bits = FreeImage_GetBits(dib);
//get the image width and height
width = FreeImage_GetWidth(dib);
height = FreeImage_GetHeight(dib);
//if this somehow one of these failed (they shouldn't), return failure
if((bits == 0) || (width == 0) || (height == 0))
return 0;

//if this texture ID is in use, unload the current texture
//if(m_texID.find(texID) != m_texID.end())
// glDeleteTextures(1, &(m_texID[texID]));

//generate an OpenGL texture ID for this texture
glGenTextures(1, &gl_texID);
//store the texture ID mapping
//m_texID[texID] = gl_texID;
//bind to the new texture ID
glBindTexture(GL_TEXTURE_2D, gl_texID);
//store the texture data for OpenGL use
glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height,
border, image_format, GL_UNSIGNED_BYTE, bits);

//Free FreeImage's copy of the data
FreeImage_Unload(dib);

//return success
return 1;
}
void BindTexture(const unsigned int texID)
{
glBindTexture(GL_TEXTURE_2D,gl_texID );
}
struct particle
{
public:
vector float Position;
float Posx,Posy,Posz,initialPosx,initialPosy,initialPosz;
float Velx,Vely,Velz,initialVelx,initialVely,initialVelz;

float Sizex,Sizey,Sizez,initialSizex,initialSizey,initialSizez;
float Colourx,Coloury,Colourz,initialColourx,initialColoury,initialColourz;

int LifeSpan;
int Age;
int Degree;
bool Alive;
bool Visible;
bool Activated;

};
typedef struct particle Particle;

struct particleSystem
{
public:
Particle* P;

int NumberofParticles;
int currentParticle;
};
typedef struct particleSystem ParticleSystem;


int timeswitch = 0;
float timeNow = 0;
float endTime = 0;
float currentTime = 0;

float RandNumber(float lowNo,float highNo)
{
return lowNo +(highNo-lowNo)*((float)rand()/((float)RAND_MAX+1.0f));
}

int AddGap(float TimeGap)
{
if(timeswitch == 0)
{
timeNow = glutGet(GLUT_ELAPSED_TIME);
endTime = timeNow + TimeGap;
timeswitch = 1;
}
currentTime = glutGet(GLUT_ELAPSED_TIME);

if(currentTime >= endTime)
{
timeswitch = 0;
return 1;
}
return 0;
}
void InitialiseParticles(ParticleSystem* ps,int numParticles)
{
ps->currentParticle = 0;
ps->P = new Particle[numParticles];

ps->NumberofParticles = numParticles;
for(int i = 0;i<ps->NumberofParticles;i = i+1)
{
ps->P.Alive = true;
ps->P.LifeSpan = 500;

ps->P.Position = (vector float){RandNumber(-50,50), 0, 0, 0};
ps->P.Posx = RandNumber(-50,50);
ps->P.Posy = 0;
ps->P.Posz = 0;

ps->P.Velx = 0;
ps->P.Vely = 0.1;
ps->P.Velz = 0;

ps->P.Sizex = 5;
ps->P.Sizey = 5;
ps->P.Sizez = 0;
ps->P.Colourx = 0;
ps->P.Coloury = 1;
ps->P.Colourz= 0;
ps->P.Age = 0;
ps->P.Degree = 0;



ps->P.initialPosx = ps->P.Posx;
ps->P.initialPosy = ps->P.Posy;
ps->P.initialPosz = ps->P.Posz;

ps->P.initialVelx = ps->P.Velx;
ps->P.initialVely = ps->P.Vely;
ps->P.initialVelz = ps->P.Velz;

ps->P.initialSizex = ps->P.Sizex;
ps->P.initialSizey = ps->P.Sizey;
ps->P.initialSizez = ps->P.Sizez;
ps->P.initialColourx = ps->P.Colourx;
ps->P.initialColoury = ps->P.Coloury;
ps->P.initialColourz =ps-> P.Colourz;
}
}
void ActivateParticles(ParticleSystem* ps,int gap,int intensity)
{
if(ps->currentParticle < ps->NumberofParticles)
{
if(AddGap(gap) == 1 )
{
for(int i = 0;i< intensity;i++)
{
ps->P[ps->currentParticle].Activated = true;
ps->currentParticle++;
}
if(ps->currentParticle >= ps->NumberofParticles)
ps->currentParticle = 0;
}
}
}
void PSUpdate(ParticleSystem* ps)
{
for(int i = 0;i < ps->NumberofParticles;i++)
{
if(ps->P.Activated == true)
{
ps->P.Posx+=ps->P.Velx;
ps->P.Posy+=ps->P.Vely;
ps->P.Posz+=ps->P.Velz;
ps->P.Age++;
}
}
}
void PSRender(ParticleSystem* ps,bool repeat)
{BindTexture(1);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

for(int i = 0;i<ps->NumberofParticles;i++)
{
if(ps->P.Activated == true)
{
if(ps->P.Age < ps->P.LifeSpan)
{
glEnable(GL_TEXTURE_2D);

glPushMatrix();

glTranslatef(ps->P.Posx, ps->P.Posy, ps->P.Posz);
glRotatef(ps->P.Degree,0,1,0);

glBegin(GL_QUADS);

glTexCoord2f(0.0f,0.0f);glVertex3f(-ps->P.Sizex, ps->P.Sizey, ps->P.Sizez);
glTexCoord2f(0.0f,1.0f);glVertex3f(ps->P.Sizex, ps->P.Sizey, ps->P.Sizez);
glTexCoord2f(1.0f,1.0f);glVertex3f(ps->P.Sizex, -ps->P.Sizey, ps->P.Sizez);
glTexCoord2f(1.0f,0.0f);glVertex3f(-ps->P.Sizex, -ps->P.Sizey, ps->P.Sizez);


glEnd();

glPopMatrix();

glFlush();

}
else{
if(repeat == true)
{
ps->P.Activated = false;
ps->P.Posx = ps->P.initialPosx;
ps->P.Posy = ps->P.initialPosy;
ps->P.Posz = ps->P.initialPosz;
ps->P.Velx = ps->P.initialVelx;
ps->P.Vely = ps->P.initialVely;
ps->P.Velz = ps->P.initialVelz;
ps->P.Sizex = ps->P.initialSizex;
ps->P.Sizey = ps->P.initialSizey;
ps->P.Sizez = ps->P.initialSizez;
ps->P.Colourx = ps->P.initialColourx;
ps->P.Coloury = ps->P.initialColoury;
ps->P.Colourz = ps->P.initialColourz;
ps->P.Age = 0;
}
}
}
}

}
/* function to be called for window display */
void display(void);
ParticleSystem *PS = new ParticleSystem;
int main(int argc, char **argv){

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(WIDTH, HEIGHT);
glutInitWindowPosition(200, 100);
glutCreateWindow("Particle Engine");

FreeImage_Initialise();
int t = LoadTexture("texture.bmp",1,GL_RGB,GL_RGB,0,0);
if(t == 0)
return 0;


InitialiseParticles(PS,100);

glTranslatef(0,0,-200);
glutDisplayFunc(display);
glutIdleFunc(display);
glMatrixMode(GL_PROJECTION);

gluPerspective(45,1.0,10.0,200.0);

glMatrixMode(GL_MODELVIEW);


/* Start the processing loop */
glutMainLoop();
return 0;
}

void display(void) {
ActivateParticles(PS,1000,2);
PSUpdate(PS);
PSRender(PS,true);

glutSwapBuffers();

}
Quote:Original post by Frenzy123

Here is the full program which i didnt initially link due to its length and mostly irrelevant to my problem.

Well, the source tags are your friend - and ours. Please add them to your posts, since they make them more readable.

Example:
void BindTexture(const unsigned int texID){  glBindTexture(GL_TEXTURE_2D,gl_texID );}

In that call, you still don't use the texID parameter.
Did you verify that gl_texID is correct?
Did you check the error state after the glGenTextures(...), glBindTexture(...) and glTexImage2D(...) calls?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Yea the TexID parameter was part of the code i took from the example it used a map which to simplify things i removed and replaced with the GLuint gl_texID variable, which explains why the function BindTexture(const unsigned int texID)
doesnt use texID, i changed the code so that it doesnt use the parameter and i realise i should have tidied it up a little bit more :P but i have been stuck trying to get a single texture to load for the last few days. As far as i can tell the LoadTexture function uses the right texture as it doesnt return 0 at any point. As far as "Did you check the error state after the glGenTextures(...), glBindTexture(...) and glTexImage2D(...) calls?" i am unsure of how to do this. There is no way i can debug my code using this compiler from what i have seen. The only thing i can do is throw in an if statement and return 0(or any number to stop the program from running in the Main function. Is there a simple if statement i can use to check to see if those functions are doing what theyre meant to be doing ? I have assumed that if the function has found the correct textrue file that it would be doing this correctly.

Again thankyou for any feedback


Ok so i spent the last couple hours including FreeImage into a PC version of my particle engine. I used the exact code that the openGL example gives you(which is a texture manager class to do it all for you). But it doesnt work.It seems to get through the loadtexture function and it also manages to find the saved texture with the bindtexture function, but yet it still doesnt load the texture. Has anybody else had any problems with FreeImage. This is such a small part of my project i really didnt want to spend so much time trying to get a texture to load in my project, i guess i was naive to think that this would only take a few hours.

This topic is closed to new replies.

Advertisement