-
Notifications
You must be signed in to change notification settings - Fork 0
/
texture.cpp
31 lines (23 loc) · 983 Bytes
/
texture.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
#include <vector>
#include "ppm.h"
#include "glsupport.h"
#include "texture.h"
#include "asstcommon.h"
using namespace std;
ImageTexture::ImageTexture(const char* ppmFileName, bool srgb) {
int width, height;
vector<PackedPixel> pixData;
ppmRead(ppmFileName, width, height, pixData);
glBindTexture(GL_TEXTURE_2D, tex);
if (g_Gl2Compatible)
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, (!srgb) || g_Gl2Compatible ? GL_RGB : GL_SRGB, width, height,
0, GL_RGB, GL_UNSIGNED_BYTE, &pixData[0]);
if (!g_Gl2Compatible)
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
checkGlErrors();
}