• Advertisement
Sign in to follow this  

OpenGL .dll to .a ?

This topic is 3311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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).

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
.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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites
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();

}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Well, checking for OpenGL errors can be done via the glGetError function, right after the call that might produce the error. You could return 0 if the error value is not GL_NO_ERROR.

Share this post


Link to post
Share on other sites
//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);


http://www.opengl.org/wiki/Common_Mistakes#Creating_a_Texture

Share this post


Link to post
Share on other sites
Late last night i finally got it working. It turns out that the code provided in the texture manager that comes with FreeImage for openGL doesnt work. After googling i found some code with the extra bits in that the code was missing and now it works on both the PS3 and my PC. Thanks for your help guys.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By LifeArtist
      Good Evening,
      I want to make a 2D game which involves displaying some debug information. Especially for collision, enemy sights and so on ...
      First of I was thinking about all those shapes which I need will need for debugging purposes: circles, rectangles, lines, polygons.
      I am really stucked right now because of the fundamental question:
      Where do I store my vertices positions for each line (object)? Currently I am not using a model matrix because I am using orthographic projection and set the final position within the VBO. That means that if I add a new line I would have to expand the "points" array and re-upload (recall glBufferData) it every time. The other method would be to use a model matrix and a fixed vbo for a line but it would be also messy to exactly create a line from (0,0) to (100,20) calculating the rotation and scale to make it fit.
      If I proceed with option 1 "updating the array each frame" I was thinking of having 4 draw calls every frame for the lines vao, polygons vao and so on. 
      In addition to that I am planning to use some sort of ECS based architecture. So the other question would be:
      Should I treat those debug objects as entities/components?
      For me it would make sense to treat them as entities but that's creates a new issue with the previous array approach because it would have for example a transform and render component. A special render component for debug objects (no texture etc) ... For me the transform component is also just a matrix but how would I then define a line?
      Treating them as components would'nt be a good idea in my eyes because then I would always need an entity. Well entity is just an id !? So maybe its a component?
      Regards,
      LifeArtist
    • By QQemka
      Hello. I am coding a small thingy in my spare time. All i want to achieve is to load a heightmap (as the lowest possible walking terrain), some static meshes (elements of the environment) and a dynamic character (meaning i can move, collide with heightmap/static meshes and hold a varying item in a hand ). Got a bunch of questions, or rather problems i can't find solution to myself. Nearly all are deal with graphics/gpu, not the coding part. My c++ is on high enough level.
      Let's go:
      Heightmap - i obviously want it to be textured, size is hardcoded to 256x256 squares. I can't have one huge texture stretched over entire terrain cause every pixel would be enormous. Thats why i decided to use 2 specified textures. First will be a tileset consisting of 16 square tiles (u v range from 0 to 0.25 for first tile and so on) and second a 256x256 buffer with 0-15 value representing index of the tile from tileset for every heigtmap square. Problem is, how do i blend the edges nicely and make some computationally cheap changes so its not obvious there are only 16 tiles? Is it possible to generate such terrain with some existing program?
      Collisions - i want to use bounding sphere and aabb. But should i store them for a model or entity instance? Meaning i have 20 same trees spawned using the same tree model, but every entity got its own transformation (position, scale etc). Storing collision component per instance grats faster access + is precalculated and transformed (takes additional memory, but who cares?), so i stick with this, right? What should i do if object is dynamically rotated? The aabb is no longer aligned and calculating per vertex min/max everytime object rotates/scales is pretty expensive, right?
      Drawing aabb - problem similar to above (storing aabb data per instance or model). This time in my opinion per model is enough since every instance also does not have own vertex buffer but uses the shared one (so 20 trees share reference to one tree model). So rendering aabb is about taking the model's aabb, transforming with instance matrix and voila. What about aabb vertex buffer (this is more of a cosmetic question, just curious, bumped onto it in time of writing this). Is it better to make it as 8 points and index buffer (12 lines), or only 2 vertices with min/max x/y/z and having the shaders dynamically generate 6 other vertices and draw the box? Or maybe there should be just ONE 1x1x1 cube box template moved/scaled per entity?
      What if one model got a diffuse texture and a normal map, and other has only diffuse? Should i pass some bool flag to shader with that info, or just assume that my game supports only diffuse maps without fancy stuff?
      There were several more but i forgot/solved them at time of writing
      Thanks in advance
    • By RenanRR
      Hi All,
      I'm reading the tutorials from learnOpengl site (nice site) and I'm having a question on the camera (https://learnopengl.com/Getting-started/Camera).
      I always saw the camera being manipulated with the lookat, but in tutorial I saw the camera being changed through the MVP arrays, which do not seem to be camera, but rather the scene that changes:
      Vertex Shader:
      #version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(aPos, 1.0f); TexCoord = vec2(aTexCoord.x, aTexCoord.y); } then, the matrix manipulated:
      ..... glm::mat4 projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); ourShader.setMat4("projection", projection); .... glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp); ourShader.setMat4("view", view); .... model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f)); ourShader.setMat4("model", model);  
      So, some doubts:
      - Why use it like that?
      - Is it okay to manipulate the camera that way?
      -in this way, are not the vertex's positions that changes instead of the camera?
      - I need to pass MVP to all shaders of object in my scenes ?
       
      What it seems, is that the camera stands still and the scenery that changes...
      it's right?
       
       
      Thank you
       
    • By dpadam450
      Sampling a floating point texture where the alpha channel holds 4-bytes of packed data into the float. I don't know how to cast the raw memory to treat it as an integer so I can perform bit-shifting operations.

      int rgbValue = int(textureSample.w);//4 bytes of data packed as color
      // algorithm might not be correct and endianness might need switching.
      vec3 extractedData = vec3(  rgbValue & 0xFF000000,  (rgbValue << 8) & 0xFF000000, (rgbValue << 16) & 0xFF000000);
      extractedData /= 255.0f;
    • By Devashish Khandelwal
      While writing a simple renderer using OpenGL, I faced an issue with the glGetUniformLocation function. For some reason, the location is coming to be -1.
      Anyone has any idea .. what should I do?
  • Advertisement