#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/glu.h>
using namespace std;
bool mouseLeftDown;
bool mouseRightDown;
float mouseX, mouseY;
float cameraDistance;
float cameraAngleX;
float cameraAngleY;
void init()
{
glClearColor(0,0,0,0);
GLfloat light_position[]={1,1,1,0};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
GLfloat light_diffuse[]={1,1,1,1};
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
GLfloat mat_emission[] = {1, 0, 0, 0.0}; //决定了三为物体表面颜色
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
//glColorMaterial(GL_FRONT,GL_DIFFUSE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glTranslatef(0, 0, cameraDistance);
glRotatef(cameraAngleX, 1, 0, 0);
glRotatef(cameraAngleY, 0, 1, 0);
//glColorMaterial(GL_FRONT,GL_DIFFUSE);
//glColor3f(1,0,0);//这个函数只对二维图形绘制起作用
glutSolidCube(1);
glFlush();
}
void mouse(int button,int state,int x,int y)
{
//printf("mouse\n");
mouseX = x;
mouseY = y;
if(button == GLUT_LEFT_BUTTON)
{
if(state == GLUT_DOWN)
{
mouseLeftDown = true;
}
else if(state == GLUT_UP)
mouseLeftDown = false;
}
else if(butt
小白学opengl之三维物体绘制
最新推荐文章于 2022-11-02 15:56:32 发布