Hi,
I am newbie to openGL, i need to place different images on the surface of the cube using “libjpeg” library for placing images. i am using c in ubuntu.
help me please.
waiting for your valuable answer.
Advance Thanks
Hi,
I am newbie to openGL, i need to place different images on the surface of the cube using “libjpeg” library for placing images. i am using c in ubuntu.
help me please.
waiting for your valuable answer.
Advance Thanks
I know how to create cube in openGL, but i don’t know how to place images on surface of the cube.
The code below will give you the 3D cube :
code :
#include <GL/gl.h>
#include <GL/glut.h>
GLfloat gAngle = 0.0;
void timer(int value)
{
const int desiredFPS=120;
glutTimerFunc(1000/desiredFPS, timer, ++value);
GLfloat dt = 1./desiredFPS;
gAngle += dt*360./8.;
glutPostRedisplay();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,0,-100);
glRotatef(gAngle,1.,1.,1.);
glutWireCube(20.);
glPopMatrix();
glutSwapBuffers();
}
void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);
GLdouble Vol = 10*1.8;
GLdouble Left=-Vol;
GLdouble Right=Vol;
GLdouble Bottom=-Vol;
GLdouble Top=Vol;
GLdouble Near=0;
GLdouble Far=2*Vol;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(Left, Right, Bottom, Top, Near, Far);
GLdouble eyeX=0;
GLdouble eyeY=0;
GLdouble eyeZ=-100+Vol;
GLdouble centerX=0;
GLdouble centerY=0;
GLdouble centerZ=-100;
GLdouble upX=0;
GLdouble upY=1;
GLdouble upZ=0;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ,
centerX,centerY,centerZ,
upX,upY,upZ);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutCreateWindow(“FPS test /w glutTimerFunc”);
glutTimerFunc(0,timer,0);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
init();
glutMainLoop();
return 0;
}
Hi Thank You,
I need to place different images on the sides of the cube using libjpeg library.
I have code for both cube and decompression of the JPEG images, but i don’t know how to place jpeg images on the cube.
please give some snippet of code it will help me a lot.
waiting for reply.
Thanking You.
Hi Thank you very much.
As i am newbie to openGL, i dint get the correct information about placing different images on the sides of the cube using libjpeg library from above website. please please guide me.
It will help me a lot.
Hi,
My question is what is the function of below code. please explain it How it is functioning.
code :
int load_texture (const char * filename,
unsigned char * dest,
const int format,
const unsigned int size)
{
FILE *fd;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
unsigned char * line;
cinfo.err = jpeg_std_error (&jerr);
jpeg_create_decompress (&cinfo);
if (0 == (fd = fopen(filename, “rb”)))
return 1;
jpeg_stdio_src (&cinfo, fd);
jpeg_read_header (&cinfo, TRUE);
if ((cinfo.image_width != size) || (cinfo.image_height != size))
return 1;
if (GL_RGB == format)
{
if (cinfo.out_color_space == JCS_GRAYSCALE)
return 1;
}
else
if (cinfo.out_color_space != JCS_GRAYSCALE)
return 1;
jpeg_start_decompress (&cinfo);
while (cinfo.output_scanline < cinfo.output_height)
{
line = dest +
(GL_RGB == format ? 3 * size : size) * cinfo.output_scanline;
jpeg_read_scanlines (&cinfo, &line, 1);
}
jpeg_finish_decompress (&cinfo);
jpeg_destroy_decompress (&cinfo);
return 0;
}
please help me from this… Advance Thanks.
Hi,
This code is going to fill a destination buffer (unsigned char* dest argument) from a JPEG file (const char* filename argument).
After calling this function with your JPEG file and a correct buffer as destination, you should use texture mapping OpenGL functions as explained in http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06.
Best,
Hi,
As i am new to openGL.
How to scale the size of an image ?
please tell me.