include glut include Windows include cstdio include iostream GLUquadri

  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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "glut.h"
#include <Windows.h>
#include <cstdio>
#include <iostream>
GLUquadricObj* theqw;
GLUnurbsObj* theNurb;
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, 1.0 * 0.55,
0.0, 0.866 * 0.55, 0.3 * 0.55, 1.0 * 0.55,
-0.5, 0.0, -0.3, 1.0,
-0.5, 0.0, 0.3, 1.0};
GLfloat TexP[] = {1.0, 0.0, 0.0, 0.0};
GLfloat TexP1[] = {0.0, 1.0, 0.0, 0.0};
GLfloat TexP2[] = {0.0, 0.0, 1.0, 0.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, 1, 1, 0, 1, 1};
GLubyte* Iz_RGB;
void init()
{
glEnable(GL_DEPTH_TEST);
glClearColor(0.1, 0.98, 0.3, 1.0);
theqw = gluNewQuadric();
theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
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);
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);
free(Iz_RGB);
}
void file_read(const char* filename)
{
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;
Iz_RGB = (GLubyte*)malloc(w * h * 3);
fread(Iz_RGB, w * h * 3, 1, MyFile);
fclose(MyFile);
for (int ii = 0; ii < w * h * 3; ii += 3)
{
GLubyte m1 = Iz_RGB[ii];
Iz_RGB[ii] = Iz_RGB[ii + 2];
Iz_RGB[ii + 2] = m1;
}
}
void generateKnot(int pointCount, int degree, double* knot, int& knotSize)
{
int k = degree + 1;
int n = pointCount - 1;
for (int i = 1; i <= n + k + 1; ++i)
{
if (i <= k)
{
knot[i - 1] = 0;
}
else
if(i <= n + 1)
{
knot[i - 1] = i - k;
}
else
{
knot[i - 1] = n - k + 2;
}
}
knotSize = n + k + 1;
}
void Display()
{
GLfloat knot[] = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
GLfloat knot1[] = {0.0, 0.0, 1.0, 1.0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef(0.1, 1.0, 1.0, 1.0);
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, TexP1);
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();
}
void main()
{
file_read("пидрила.bmp");
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(480, 480);
glutInitWindowPosition(100, 100);
glutCreateWindow(" dfa");
init();
glutDisplayFunc(Display);
glutMainLoop();
}