Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: view the scene from all directions

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    8

    view the scene from all directions

    Hi all,

    I am a biginner in opengl, i want to write a program that i can show the environmet from all direction, i don't know how should i do?!!
    it's my code!

    #include <GL/gl.h>
    #include <GL/glut.h>
    #include <iostream>


    using namespace std;


    void init(void);
    void display(void);
    void changeSize(int w, int h);
    void Keyboard(unsigned char key, int x, int y);

    int fov = 50;

    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);

    glutInitWindowPosition(100, 100);
    glutInitWindowSize(400, 300);
    glutCreateWindow("test");

    //glutReshapeFunc(changeSize);
    glutKeyboardFunc (Keyboard);
    glutDisplayFunc(display);

    init();

    glutMainLoop();
    }


    void init()
    {
    glClearColor(0.0,0.0,0.0,0.0);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(20.0, 1, 2.0, 40.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();View all Si
    gluLookAt(0, 17, 19,0, 0, 0,0, 1, 0);

    //glRotated(-45,0,0,1);
    glRotated(90,1,0,0);
    }


    void display()
    {
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fov, 1, 2.0, 40.0);

    // glMatrixMode(GL_MODELVIEW);
    // glLoadIdentity();
    // glRotated(45,0,1,0);

    glColor3f(1.0,0.0,0.0);
    glBegin(GL_QUADS);
    glVertex3f(-6.5f, -3.5f, -6.5f);
    glVertex3f(-6.5f, -3.5f, 6.5f);
    glVertex3f(6.5f, -3.5f, 6.5f);
    glVertex3f(6.5f, -3.5f, -6.5f);
    glEnd();

    glFlush();
    }


    void changeSize(int w, int h)
    {
    if(h == 0)
    h = 1;
    float ratio = 1.0* w / h;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, w, h);
    gluPerspective(90,ratio,1,1000);
    }


    void Keyboard(unsigned char key, int x, int y)
    {
    switch (key)
    {
    case 43:
    fov += 5;
    break;//+
    case 45:
    fov -= 5;
    break;//-
    }

    glutPostRedisplay();
    }
    Last edited by new_beginner; 09-23-2013 at 06:38 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
  •