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();
}