include Windows include cstdio include gl glut using namespace std GLf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <Windows.h>
#include <cstdio>
#include <gl/glut.h>
using namespace std;
GLfloat ctlarray[3][2][4] = {0.5, 0.0, -0.3, 1.0,
0.5, 0.0, 0.3, 1.0,
0.0, 0.866*0.55, -0.3 * 0.55, 0.55,
0.0, 0.866*0.55, 0.3 * 0.55, 0.55,
-0.5, 0.0, -0.3, 1.0,
-0.5, 0.0, 0.3, 1.0};
GLfloat TexP[] = { 1, 0, 0, 0};
GLfloat TexP1[] = {0, 1, 0, 0};
GLfloat TexP2[] = {0, 0, 1, 0};
GLubyte TexI[] = {255, 0, 0,
255, 0, 0,
255, 255, 0,
255, 255, 0,
0, 255, 0,
0, 255, 0,
0, 0, 255,
0, 0, 255};
GLfloat texpts[2][2][2] = {0, 0, 0, 2, 2, 0, 2, 2};
GLUnurbsObj* theNurb;
GLUquadricObj* theqw;
void init(){
glClearColor(0.5, 0.75, 0.75, 1);
theNurb = gluNewNurbsRenderer();
theqw = gluNewQuadric();
glEnable(GL_DEPTH_TEST);
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage1D(GL_TEXTURE_1D, 0, 3, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, TexI);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_1D);
}
void display() {
GLfloat knot[] = {0, 0, 0, 1, 1, 1};
GLfloat knot1[] = {0, 0, 1, 1};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glRotatef(1, 1, 1, 1);
glColor3f(1, 0, 0);
glEnable(GL_TEXTURE_GEN_S);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_OBJECT_PLANE, TexP2);
gluSphere(theqw, 0.3, 50, 50);
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,
6, knot,
4, knot1,
8, 4,
&ctlarray[0][0][0],
3, 2,
GL_MAP2_VERTEX_4);
gluEndSurface(theNurb);
glutPostRedisplay();
glutSwapBuffers();
}
int main() {
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(720, 1280);
glutInitWindowPosition(200, 200);
glutCreateWindow("Title");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}