C++,OpenGL高手来,

来源:百度知道 编辑:UC知道 时间:2024/05/01 22:28:51
#include <windows.h>
#include <math.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>

void init();
void CALLBACK reshape(GLsizei w,GLsizei h);
void CALLBACK display();
GLfloat s,h;
void CALLBACK display()
{glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(5,5,h,s,0,0,0,1,0);
glRotatef(30,1,1,0);
//glClear3f(0,0,0);
GLfloat RAD=3.1415926/180;
GLfloat x,y,z,r;
int i,j;
for(i=0;i<180;i+=5)
{glBegin(GL_LINE_LOOP);
r=2*sin(i*RAD);
z=2*cos(i*RAD);
for(j=00;j<360;j+=10)
x=r*cos(i*RAD);
y=r*sin(i*RAD);
glVertex3f(x,y,z);
}
glEnd;
for(j=0;j<360;j+=10)
{
glBegin(GL_LINE_LOOP);
for(i=0;i<=180;i+=10)
{
r=2*sin(i*RAD);
z=2*cos(i*RAD);
x=r*cos(i*RAD);
y=r*sin(i*RA

给你的程序做了修改,编译可以过了,不过显示一片白,程序逻辑有问题,自己查一下好了,我将改完的代码放在下面:
#include <windows.h>
#include <math.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>

void init();
void CALLBACK reshape(GLsizei w,GLsizei h);
void CALLBACK display();
GLfloat s,h;
void CALLBACK display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(5,5,h,s,0,0,0,1,0);
glRotatef(30,1,1,0);
//glClear3f(0,0,0);
GLfloat RAD=3.1415926/180;
GLfloat x,y,z,r;
int i,j;
for(i=0;i<180;i+=5)
{
glBegin(GL_LINE_LOOP);
r=2*sin(i*RAD);
z=2*cos(i*RAD);
for(j=00;j<360;j+=10)
x=r*cos(i*RAD);
y=r*sin(i*RAD);
glVertex3f(x,y,z);
glEnd();
}

for(j=0;j<360;j+=10)
{
glBegin(GL_LINE_LOOP);
for(i=0;i<=180;i+=10)
{
r=2*sin(i*RAD);