VPN termux about China.net
obj exemple
#include<GL/gl.h>
#include<GL/glut.h>
#include<stdio.h>
//globals
GLuint car;
float carrot;
//other functions and main
//.obj loader code
void loadObj(char *fname)
{
FILE *fp;
int read;
GLfloat x, y, z;
char ch;
car=glGenLists(1);
fp=fopen(fname,"r");
if (!fp)
{
printf("can't open file %s\n", fname);
exit(1);
}
glPointSize(2.0);
glNewList(car, GL_COMPILE);
{
glPushMatrix();
glBegin(GL_POINTS);
while(!(feof(fp)))
{
read=fscanf(fp,"%c %f %f %f",&ch,&x,&y,&z);
if(read==4&&ch=='v')
{
glVertex3f(x,y,z);
}
}
glEnd();
}
glPopMatrix();
glEndList();
fclose(fp);
}
//.obj loader code ends here
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-25,25,-2,2,0.1,100);
glMatrixMode(GL_MODELVIEW);
}
void drawCar()
{
glPushMatrix();
glColor3f(1.0,0.23,0.27);
glTranslatef(0.0, -0.9, 0.0);
glScalef(0.4,0.4,0.4);
glRotatef(carrot,0,1,0);
glCallList(car);
glPopMatrix();
carrot=carrot+0.6;
if(carrot>360)carrot=carrot-360;
}
void display(void)
{
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
drawCar();
glutSwapBuffers(); //swap the buffers
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(1000,750);
glutInitWindowPosition(20,20);
glutCreateWindow("ObjLoader");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
loadObj("aphroditegirl.obj");
glutMainLoop();
return 0;
}
#include<GL/gl.h>
#include<GL/glut.h>
#include<stdio.h>
//globals
GLuint car;
float carrot;
//other functions and main
//.obj loader code
void loadObj(char *fname)
{
FILE *fp;
int read;
GLfloat x, y, z;
char ch;
car=glGenLists(1);
fp=fopen(fname,"r");
if (!fp)
{
printf("can't open file %s\n", fname);
exit(1);
}
glPointSize(2.0);
glNewList(car, GL_COMPILE);
{
glPushMatrix();
glBegin(GL_POINTS);
while(!(feof(fp)))
{
read=fscanf(fp,"%c %f %f %f",&ch,&x,&y,&z);
if(read==4&&ch=='v')
{
glVertex3f(x,y,z);
}
}
glEnd();
}
glPopMatrix();
glEndList();
fclose(fp);
}
//.obj loader code ends here
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-25,25,-2,2,0.1,100);
glMatrixMode(GL_MODELVIEW);
}
void drawCar()
{
glPushMatrix();
glColor3f(1.0,0.23,0.27);
glTranslatef(0.0, -0.9, 0.0);
glScalef(0.4,0.4,0.4);
glRotatef(carrot,0,1,0);
glCallList(car);
glPopMatrix();
carrot=carrot+0.6;
if(carrot>360)carrot=carrot-360;
}
void display(void)
{
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
drawCar();
glutSwapBuffers(); //swap the buffers
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(1000,750);
glutInitWindowPosition(20,20);
glutCreateWindow("ObjLoader");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
loadObj("aphroditegirl.obj");
glutMainLoop();
return 0;
}
Subscribe to:
Posts (Atom)
No comments:
Post a Comment