PDA

View Full Version : help with library on ubuntu



sanlegas
05-21-2013, 07:30 PM
i have problem with bitmap, when i run my code, the console show me the next error:
undefined reference to `LoadDIBitmap'
the library is defined in my code


#include <GL/glut.h>
#include <math.h>
# include <stdio.h>
# include <string.h>
#include <GL/bitmap.h>
BITMAPINFO *imginfo;
GLubyte *img;
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0); //establece el color de la ventana de visualización en blanco
glMatrixMode(GL_PROJECTION); //establece los parámetros de proyección
gluOrtho2D(0.0,210.0,0.0,210.0); //define una matriz deproyección ortográfica 2D, esl amitad de lo que se especificó en
//en windowsSize.
}
void tex(char *textura)
{

//img = LoadDIBitmap("1.bmp", &imginfo);
img = LoadDIBitmap(textura, &imginfo);

glTexImage2D(GL_TEXTURE_2D, 0, 3,imginfo->bmiHeader.biWidth,imginfo->bmiHeader.biHeight, 0, GL_RGB,GL_UNSIGNED_BYTE, img);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);



}

void textura()
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
}

void cuadrado(void)
{

GLfloat angulo;
int i;
glBegin(GL_LINES);
for (i=0; i<360; i+=3)
{
angulo = (GLfloat)i*3.14159f/180.0f; // grados a radianes
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(cos(angulo), sin(angulo), 0.0f);
}
glEnd();//Finaliza el dibujo
//glFlush();
glPushMatrix();
glColor3f(3,4,0.5);
tex("1.bmp");
glutSolidSphere(30,60,60);
textura();
glPopMatrix();

}
void lee()
{
cuadrado();
glFlush();
}

int main(int argc, char ** argv)
{

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //Funcion Main
glutInitWindowPosition(20,20); //Posicion de Ventana
glutInitWindowSize(600,450); //Cambiar Tamaño de Ventana
glutCreateWindow("Figuras OpenGL"); //Crea y cambia el nombre de la ventana
init();

glutDisplayFunc(lee);//se pintan todas las figuras

glutMainLoop(); //Loop

return 0;




return 0;
}


Its where is my library
https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-ash4/401775_10200717813462031_1553933637_n.jpg


thanks

RigidBody
05-22-2013, 07:23 AM
i cannot remember that i've ever seen a bitmap.h in /usr/include/GL under linux.
did you copy the bitmap.h there manually from a windows installation?

sanlegas
05-28-2013, 12:34 PM
yes, this library i think is only for windows, well what its library for texture for linux? a thanks rigid

The Little Body
05-28-2013, 05:50 PM
You can use DevIL http://openil.sourceforge.net/, this is a relatively simple library to use

DevIL can handle a very big numbers of graphics files formats such as .jpg, .tif, .tga, .bmp, .pcx, etc ...

Here an example code :


#include <IL/il.h>
#include <GL/glut.h>


#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480

int width = DEFAULT_WIDTH;
int height = DEFAULT_HEIGHT;

/* Handler for window-repaint event. Called back when the window first appears and
whenever the window needs to be re-painted. */
void display()
{
// Clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Operate on model-view matrix

/* Draw a quad */
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(0, 0);
glTexCoord2i(0, 1); glVertex2i(0, height);
glTexCoord2i(1, 1); glVertex2i(width, height);
glTexCoord2i(1, 0); glVertex2i(width, 0);
glEnd();

glutSwapBuffers();
}

/* Handler for window re-size event. Called back when the window first appears and
whenever the window is re-sized with its new width and height */
void reshape(GLsizei newwidth, GLsizei newheight)
{
// Set the viewport to cover the new window
glViewport(0, 0, width=newwidth, height=newheight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, width, height, 0.0, 0.0, 100.0);
glMatrixMode(GL_MODELVIEW);

glutPostRedisplay();
}


/* Initialize OpenGL Graphics */
void initGL(int w, int h)
{
glViewport(0, 0, w, h); // use a screen size of WIDTH x HEIGHT
glEnable(GL_TEXTURE_2D); // Enable 2D texturing

glMatrixMode(GL_PROJECTION); // Make a simple 2D projection on the entire window
glLoadIdentity();
glOrtho(0.0, w, h, 0.0, 0.0, 100.0);

glMatrixMode(GL_MODELVIEW); // Set the matrix mode to object modeling

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the window
}

/* Load an image using DevIL and return the devIL handle (-1 if failure) */
int LoadImage(char *filename)
{
ILboolean success;
ILuint image;

ilGenImages(1, &image); /* Generation of one image name */
ilBindImage(image); /* Binding of image name */
success = ilLoadImage(filename); /* Loading of the image filename by DevIL */

if (success) /* If no error occured: */
{
/* Convert every colour component into unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA */
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

if (!success)
{
return -1;
}
}
else
return -1;

return image;
}

int main(int argc, char **argv)
{

GLuint texid;
int image;

if ( argc < 1)
{
/* no image file to display */
return -1;
}

/* GLUT init */
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_DOUBLE); // Enable double buffered mode
glutInitWindowSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // Set the window's initial width & height
glutCreateWindow(argv[0]); // Create window with the name of the executable
glutDisplayFunc(display); // Register callback handler for window re-paint event
glutReshapeFunc(reshape); // Register callback handler for window re-size event

/* OpenGL 2D generic init */
initGL(DEFAULT_WIDTH, DEFAULT_HEIGHT);

/* Initialization of DevIL */
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION)
{
printf("wrong DevIL version \n");
return -1;
}
ilInit();


/* load the file picture with DevIL */
image = LoadImage(argv[1]);
if ( image == -1 )
{
printf("Can't load picture file %s by DevIL \n", argv[1]);
return -1;
}

/* OpenGL texture binding of the image loaded by DevIL */
glGenTextures(1, &texid); /* Texture name generation */
glBindTexture(GL_TEXTURE_2D, texid); /* Binding of texture name */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* We will use linear interpolation for magnification filter */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* We will use linear interpolation for minifying filter */
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); /* Texture specification */

/* Main loop */
glutMainLoop();

/* Delete used resources and quit */
ilDeleteImages(1, &image); /* Because we have already copied image data into texture data we can release memory used by image. */
glDeleteTextures(1, &texid);

return 0;
}




gcc devil_example.c -lGL -lglut -lIL -o devil_example