void file_read const char filename GLubyte Iz_RGB BITMAPFILEHEADER Fil

 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
void file_read(const char *filename, GLubyte*& Iz_RGB)
{
BITMAPFILEHEADER FileHeader;
BITMAPINFOHEADER InfoHeader;
FILE* myFile = fopen(filename, "rb");
fread(&FileHeader, sizeof(FileHeader), 1, myFile);
fread(&InfoHeader, sizeof(InfoHeader), 1, myFile);
fseek(myFile, FileHeader.bfOffBits, SEEK_SET);
int w = InfoHeader.biWidth;
int h = InfoHeader.biHeight;
if (Iz_RGB) delete[] Iz_RGB;
Iz_RGB = new GLubyte[w * h * 3];
fread(Iz_RGB, w * h * 3, 1, myFile);
fclose(myFile);
for (int ii = 0; ii < w * h * 3; ii += 3)
swap(Iz_RGB[ii], Iz_RGB[ii + 2]);
}
void Display25()
{
static GLfloat ctlarray[3][2][4] =
{
0.5, 0, -0.3, 1,
0.5, 0, 0.3, 1,
0, 0.866 * 0.55, -0.3 * 0.55, 1 * 0.55,
0, 0.866 * 0.55, +0.3 * 0.55, 1 * 0.55,
-0.5, 0, -0.3, 1,
-0.5, 0, 0.3, 1,
};
static GLfloat texpts[2][2][2] = { 0, 0, 0, 1, 1, 0, 1, 1 };
static GLUnurbsObj* theNurb = gluNewNurbsRenderer();
static GLUquadricObj* theqw = gluNewQuadric();
static bool inited = false;
if (!inited)
{
glClearColor(0.1, 0.98, 0.3, 1);
glEnable(GL_DEPTH_TEST);
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLubyte* Iz_RGB = nullptr;
file_read("D:\\1.bmp", Iz_RGB);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, Iz_RGB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
gluQuadricTexture(theqw, true);
glEnable(GL_TEXTURE_2D);
inited = true;
delete[] Iz_RGB;
}
GLfloat knot[] = { 0, 0, 0, 1, 1, 1 };
GLfloat knot1[] = { 0, 0, 1, 1 };
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef(1e-1, 1, 1, 1);
glColor3f(1, 0, 0);
glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &texpts[0][0][0]);
glEnable(GL_MAP2_TEXTURE_COORD_2);
gluSphere(theqw, 0.3, 50, 50);
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb, 6, knot, 4, knot1, 2 * 4, 4, &ctlarray[0][0][0], 3, 2, GL_MAP2_VERTEX_4);
gluEndSurface(theNurb);
glutPostRedisplay();
glutSwapBuffers();
}