jhy_jhy
jhy_jhy
2017-05-26 06:42

Opengl在VS2015下一直报错

  • opengl

图片说明
代码// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include"stdlib.h"
#include"glut.h"
#pragma comment ( lib , "glut32.lib" )

GLfloat angle = 0.0f;
GLfloat multiply = 0.0f;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, 1.0f, 1.0f, 20.0f);

glLoadIdentity();
gluLookAt(0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
{
//设置一个点光源
GLfloat light_position[] = { 0.5f,0.0f,0.0f,1.0f };//(xyzw)w为1时代表点光源,0时代表方向光源
GLfloat light_ambient[] = { 0.5f,0.5f,0.5f,1.0f };//(0001)

GLfloat light_diffuse[] = { 1.0f,1.0f,1.0f,1.0f };//(1111)
GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };//(1111)

glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);//光源环境光强值

glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);//光源漫反射强值
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);//光源镜面反射强值

glEnable(GL_LIGHT0);//打开该光源

glEnable(GL_LIGHTING);//打开光照
}
{
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, 0.6f); //平移
glScaled(multiply, multiply, multiply); //缩放

glutSolidSphere(0.2, 50, 50);

}
glutSwapBuffers();
}

void rotateAndzoom(void) //旋转和缩放
{
angle += 1.0f;
if (angle >= 360.0f)

angle = 0.0f;

display();

//设置旋转
multiply += 0.01f;

if (multiply >= 2.0f)

// multiply -= 0.01f;

//if (multiply <= 1.0f)

multiply = 1.0f;

display();
//设置缩放
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

glutInitWindowPosition(400, 50);

glutInitWindowSize(800, 800);

glutCreateWindow("立体");
glutDisplayFunc(&display);
glutIdleFunc(&rotateAndzoom);//旋转
glutMainLoop();//调用该函数启动程序,所有以创建的窗口将会显示

return 0;
}

求大神帮忙看看

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答