Results 1 to 3 of 3

Thread: Losing Image On Resize

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2002
    Posts
    10

    Losing Image On Resize

    Hey all,
    I am creating a very simple scene description language to make life a litte easier. I am reading my data like: objects, light, etc. in from a file. Also I am only using single buffering. My problem is when I resize my window, I lose the image. Do I have to write a reshape function or I am missing some simple command. I have provided my code for reference. Thanks in advance.


    #include <windows.h>
    #include <gl/Gl.h>
    #include <gl/Glu.h>
    #include <Gl/Glut.h>
    #include <cstdlib>
    #include <fstream>
    #include <iostream>
    #include <string>


    using namespace std;

    const char *datName = "data.txt";
    //ifstream in(datName);
    ifstream in;


    void renderSDL(ifstream &in)
    {
    GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f};
    GLfloat mat_diffuse[] = { 1.6f, 0.0f, 0.0f, 1.0f};
    GLfloat mat_specular[] = {1.0f,1.0f,1.0f,1.0f};
    GLfloat mat_shininess[] = {80.0f};

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); //set initial ambience
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); //set intial diffusion color
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); //set initial specular settings
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); //set initial shininess for objects

    GLfloat lightIntenisity[] = { 0.9f, 0.9f, 0.9f, 1.0f};
    GLfloat light_position[] = {1.5f, 3.0f, 1.0f, 0.0f};

    glLightfv(GL_LIGHT1, GL_POSITION, light_position);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, lightIntenisity );

    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);

    glEnable(GL_LIGHTING); // Turn on lighting
    glEnable(GL_LIGHT1); // Turn on light 1

    string cmd;

    in>>cmd;

    while(!in.eof())
    {

    if(cmd == "ROTATE"){
    GLdouble angle, ux, uy, uz;
    in>>angle>>ux>>uy>>uz;
    glRotatef(angle, ux, uy, uz);
    }

    else if(cmd == "TRANSLATE"){
    GLdouble dx, dy, dz;
    in>>dx>>dy>>dz;
    glTranslatef(dx, dy, dz);
    }

    else if(cmd == "SCALE"){
    GLdouble sx, sy, sz;
    in>>sx>>sy>>sz;
    glScalef(sx, sy, sz);
    }

    else if(cmd == "PLANE"){
    GLdouble thickness;
    in>>thickness;
    glTranslated(0.5,0.5 * thickness, 0.5);
    glScaled(5.0, thickness, 5.0);
    glutSolidCube(1.0);
    }

    else if(cmd == "PUSH")
    glPushMatrix();

    else if(cmd == "POP")
    glPopMatrix();

    else if(cmd == "CUBE"){
    GLdouble size;
    in>>size;
    glutSolidCube(size);
    }

    else if(cmd == "TEAPOT"){
    GLdouble size;
    in>>size;
    glutSolidTeapot(size);
    }

    else if(cmd == "SPHERE"){
    GLdouble radius;
    in>>radius;
    glutSolidSphere(radius, 30, 30);
    }


    else if(cmd == "TORUS"){
    GLdouble innerRadius, outerRadius;
    in>>innerRadius>>outerRadius;
    glutSolidTorus(innerRadius, outerRadius, 30, 30);
    }


    else if(cmd == "CONE"){
    GLdouble radius, height;
    in>>radius>>height;
    glutSolidCone(radius, height, 30 , 30);
    }


    else if(cmd == "ICOSAHEDRON"){
    glutSolidIcosahedron();
    }

    else if(cmd == "OCTAHEDRON"){
    glutSolidOctahedron();
    }

    else if(cmd == "TETRAHEDRON"){
    glutSolidTetrahedron();
    }

    else if(cmd == "DODECAHEDRON"){
    glutSolidDodecahedron();
    }

    else if(cmd == "IDENTITYAFFINE"){
    glLoadIdentity();
    }

    else if(cmd == "!"){
    string comment;
    getline(in, comment);
    }


    else
    cout << "ERROR KEYWORD "<<cmd<<" NOT DEFINED" << endl;

    in >> cmd;
    }//end-while loop

    glFlush();

    }


    void myDisplay(void)
    {
    GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f};
    GLfloat mat_diffuse[] = { .6f, 0.6f, 0.6f, 1.0f};
    GLfloat mat_specular[] = {1.0f,1.0f,1.0f,1.0f};
    GLfloat mat_shininess[] = {80.0f};

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); //set initial ambience
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); //set intial diffusion color
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); //set initial specular settings
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); //set initial shininess for objects

    GLfloat lightIntenisity[] = { 0.9f, 0.9f, 0.9f, 1.0f};

    GLfloat light_position[] = {.5f, 1.0f, 1.0f, 0.0f};

    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntenisity );


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    double winHt = 1.0;
    glOrtho(-winHt*64/48.0, winHt*64/48.0, -winHt, winHt, 0.1, 100.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    gluLookAt(2.3, 1.3, 2, 0, 0.3, 0, 0.0, 1.0, 0.0); //View of scene, "eye"
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    renderSDL(in);

    glFlush();

    }

    void keyboard (unsigned char key, int x, int y)
    {
    switch (key)
    {
    case 'q':
    case 'Q':
    exit(0);
    break;

    default:
    break;
    }
    }


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

    in.open(datName);

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(840, 680);
    glutInitWindowPosition(20, 20);
    glutCreateWindow("SDL Static Scene");

    glutDisplayFunc(myDisplay);

    glutKeyboardFunc(keyboard);

    glutMainLoop();

    return 0;

    }

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Losing Image On Resize

    Yes make a reshape func.....

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Losing Image On Resize

    Yes, you need to handle a resize, also you should look at some openGL programming examples.

    nehe.gamedev.net

Similar Threads

  1. Window resize, image not showing
    By Pedrosanchez87 in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 02-20-2017, 12:09 AM
  2. Image Texture Resize using glsl
    By oaraf in forum OpenGL: GLSL
    Replies: 2
    Last Post: 02-16-2011, 01:22 AM
  3. Need Help on how to resize texture image...
    By G-O-H in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-10-2008, 12:05 AM
  4. Image vanishes on resize
    By Jon Jacobs in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 06-13-2008, 12:55 PM
  5. Resize Window\Resize Image
    By Cerv36 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-16-2003, 04:42 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