Results 1 to 8 of 8

Thread: how to render cube faces with different images

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    how to render cube faces with different images


    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

  2. #2
    Member Newbie
    Join Date
    Nov 2009
    Posts
    40

    Re: how to render cube faces with different images

    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(&amp;argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE);
    glutCreateWindow("FPS test /w glutTimerFunc");

    glutTimerFunc(0,timer,0);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    init();

    glutMainLoop();
    return 0;
    }

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: how to render cube faces with different images

    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.

  4. #4
    Member Contributor
    Join Date
    Jul 2009
    Posts
    53

    Re: how to render cube faces with different images

    Hi. Go to http://nehe.gamedev.net/ - there are many gl tutorial there

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: how to render cube faces with different images

    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.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: how to render cube faces with different images

    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 (&amp;jerr);
    jpeg_create_decompress (&amp;cinfo);

    if (0 == (fd = fopen(filename, "rb")))
    return 1;

    jpeg_stdio_src (&amp;cinfo, fd);
    jpeg_read_header (&amp;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 (&amp;cinfo);

    while (cinfo.output_scanline < cinfo.output_height)
    {
    line = dest +
    (GL_RGB == format ? 3 * size : size) * cinfo.output_scanline;
    jpeg_read_scanlines (&amp;cinfo, &amp;line, 1);
    }
    jpeg_finish_decompress (&amp;cinfo);
    jpeg_destroy_decompress (&amp;cinfo);
    return 0;
    }

    please help me from this.. Advance Thanks.

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2008
    Location
    France
    Posts
    25

    Re: how to render cube faces with different images

    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....asp?lesson=06.

    Best,

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: how to render cube faces with different images

    Hi,
    As i am new to openGL.


    How to scale the size of an image ?

    please tell me.

Similar Threads

  1. Invisible faces on a cube
    By MSteve in forum OpenGL ES
    Replies: 0
    Last Post: 10-26-2011, 06:22 AM
  2. Fold each faces to create a cube
    By chrisncao in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-22-2011, 05:17 PM
  3. coloring different faces of a solid cube
    By prashantgp in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-19-2002, 05:25 AM
  4. how to hide back faces of a cube
    By jyoung77 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-26-2002, 11:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean