-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttorus.cpp
138 lines (103 loc) · 3.59 KB
/
ttorus.cpp
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
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Name: CModel.cpp
* Author: Niall Moran
* License: GPL
* Desc: Implentation file for CModel class. The class contains functionality to
* parse and display wavefront .obj CModel files.
*
*/
#include "ttorus.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
void CTtorus::display(){
// select our current texture
glColor3f(1.0,1.0,1.0);
glBindTexture( GL_TEXTURE_2D, this->texture[0] );
glBegin(GL_QUADS);
glTexCoord2i( 0, 0 );
glVertex3f(0.0,0.0,1.0);
glTexCoord2i( 0, 1 );
glVertex3f(0.0,0.0,0.0);
glTexCoord2i( 1, 1 );
glVertex3f(1.0,0.0,0.0);
glTexCoord2i( 1, 0 );
glVertex3f(1.0,0.0,1.0);
glEnd();
glPushMatrix();
glTranslatef(4.0,0.0,0.0);
glBegin(GL_QUADS);
glTexCoord2i( 0, 0 );
glVertex3f(1.0,0.0,0.0);
glTexCoord2i( 1, 0 );
glVertex3f(1.0,0.0,1.0);
glTexCoord2i( 1, 1 );
glVertex3f(0.0,0.0,1.0);
glTexCoord2i( 0, 1 );
glVertex3f(0.0,0.0,0.0);
glEnd();
glPopMatrix();
/* glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
//glEnableClientState(GL_NORMAL_ARRAY);
//glNormalPointer(GL_FLOAT, 0, normals);
glColor3f(1.0,1.0,1.0);
glDrawElements(GL_TRIANGLES, face_count * 3 , GL_UNSIGNED_INT , faces );*/
}
void CTtorus::initialise() {
GLenum texture_format;
GLint nOfColors;
// load sample.png into image
SDL_Surface *image;
image=IMG_Load("sample.bmp");
//image = SDL_LoadBMP( "bumps.bmp" ) ;
if(!image) {
printf("IMG_Load: %s\n", IMG_GetError());
// handle error
}
// get the number of channels in the SDL surface
nOfColors = image->format->BytesPerPixel;
if (nOfColors == 4) // contains an alpha channel
{
if (image->format->Rmask == 0x000000ff)
texture_format = GL_RGBA;
else
texture_format = GL_BGRA;
} else if (nOfColors == 3) // no alpha channel
{
if (image->format->Rmask == 0x000000ff) {
texture_format = GL_RGB;
printf("Format is RGB\n");
} else {
texture_format = GL_BGR;
printf("Format is BGR\n");
}
} else {
printf("warning: the image is not truecolor.. this will probably break\n");
// this error should not go unhandled
}
printf("Image details: width %d, height %d\n", image->w, image->h);
printf("No. of colours: %d\n", nOfColors);
// allocate a texture name
glGenTextures( 1, &this->texture[0] );
// select our current texture
glBindTexture( GL_TEXTURE_2D, this->texture[0] );
// select modulate to mix texture with color for shading
//glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// when texture area is small, bilinear filter the closest mipmap
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
// GL_LINEAR_MIPMAP_NEAREST );
// when texture area is large, bilinear filter the original
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// the texture wraps over at the edges (repeat)
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, nOfColors , image->w, image->h, 0,
GL_BGR, GL_UNSIGNED_BYTE, image->pixels );
}
CTtorus::~CTtorus(){
}