As a newbie, i’m learning opengl. But i stuck…How to move camera + And why my cube is visible partial.
#include<GL/glut.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
float angle = 0;
float lx = 0, lz = -1;
float x = 0, z;
void SpecialKey(int key, int x, int y)
{
float fraction = 1;
cout << key << endl;
switch(key)
{
case GLUT_KEY_LEFT:
z += 1;
cout << z << endl;
break;
case GLUT_KEY_RIGHT:
case GLUT_KEY_UP:
case GLUT_KEY_DOWN:
}
}
void Box(void)
{
glColor3f(1, 1, 1);
glBegin(GL_POLYGON);
glVertex3f(0, 0, 0);
glVertex3f(10, 0, 0);
glVertex3f(10, 10, 0);
glVertex3f(0, 10, 0);
glEnd();
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
` glLoadIdentity();
gluLookAt(5, 4, z,1, 1.0f, 1,0.0f, 1.0f, 0.0f);
glPushMatrix();
glPopMatrix();
glutWireCube(10);
glutSwapBuffers();
}
void init(void)
{
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100, 100, -100, 100, 0, 10);
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("Practice");
init();
glutDisplayFunc(Display);
glutSpecialFunc(SpecialKey);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 1;
}