-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextures.cpp
154 lines (131 loc) · 5.97 KB
/
Textures.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// Textures
//
// Created by Warren R. Carithers 2016/11/22.
// Based on code created by Joe Geigel on 1/23/13.
// Copyright 2016 Rochester Institute of Technology. All rights reserved.
//
// Contributor: Jietong Chen
//
// Simple class for setting up texture mapping parameters.
//
// This code can be compiled as either C or C++.
//
#ifdef __cplusplus
#include <iostream>
#else
#include <stdio.h>
#endif
#include "Textures.h"
// this is here in case you are using SOIL;
// if you're not, it can be deleted.
#include <SOIL.h>
#include <cstdio>
#ifdef __cplusplus
using namespace std;
#endif
// the texture handle of cup
GLuint Texture::cup;
// the texture handle of foliage
GLuint Texture::foliage1;
GLuint Texture::foliage2;
GLuint Texture::foliage3;
GLuint Texture::foliage4;
///
// This function loads texture data for the GPU.
///
void loadTexture() {
// load the cup image by SOIL
Texture::cup = SOIL_load_OGL_texture( "texture/blueberry.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS |
SOIL_FLAG_INVERT_Y |
SOIL_FLAG_NTSC_SAFE_RGB |
SOIL_FLAG_COMPRESS_TO_DXT );
if( Texture::cup == 0 ) {
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
// set up the texture parameters
glBindTexture( GL_TEXTURE_2D, Texture::cup );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
// load the first foliage image by SOIL
Texture::foliage1 = SOIL_load_OGL_texture( "texture/foliage1.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS |
SOIL_FLAG_INVERT_Y |
SOIL_FLAG_NTSC_SAFE_RGB |
SOIL_FLAG_COMPRESS_TO_DXT );
if( Texture::foliage1 == 0 ) {
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
// set up the texture parameters
glBindTexture( GL_TEXTURE_2D, Texture::foliage1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
// load the second foliage image by SOIL
Texture::foliage2 = SOIL_load_OGL_texture( "texture/foliage2.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS |
SOIL_FLAG_INVERT_Y |
SOIL_FLAG_NTSC_SAFE_RGB |
SOIL_FLAG_COMPRESS_TO_DXT );
if( Texture::foliage2 == 0 ) {
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
// set up the texture parameters
glBindTexture( GL_TEXTURE_2D, Texture::foliage2 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
// load the third foliage image by SOIL
Texture::foliage3 = SOIL_load_OGL_texture( "texture/foliage3.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS |
SOIL_FLAG_INVERT_Y |
SOIL_FLAG_NTSC_SAFE_RGB |
SOIL_FLAG_COMPRESS_TO_DXT );
if( Texture::foliage3 == 0 ) {
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
// set up the texture parameters
glBindTexture( GL_TEXTURE_2D, Texture::foliage3 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
// load the fourth foliage image by SOIL
Texture::foliage4 = SOIL_load_OGL_texture( "texture/foliage4.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS |
SOIL_FLAG_INVERT_Y |
SOIL_FLAG_NTSC_SAFE_RGB |
SOIL_FLAG_COMPRESS_TO_DXT );
if( Texture::foliage4 == 0 ) {
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
// set up the texture parameters
glBindTexture( GL_TEXTURE_2D, Texture::foliage4 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
}
///
// This function sets up the parameters for texture use.
//
// @param texture - The OpenGL texture handle of the texture to use
///
void setUpTexture( GLuint texture ) {
glBindTexture( GL_TEXTURE_2D, texture );
}