-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTexture2D.cpp
More file actions
60 lines (50 loc) · 1.11 KB
/
Texture2D.cpp
File metadata and controls
60 lines (50 loc) · 1.11 KB
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
#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif
#include <gl/glew.h>
#include <gl/gl.h>
#include <cassert>
#include "Texture2D.h"
void Texture2D::bind( unsigned int unit )
{
glActiveTexture( GL_TEXTURE0 + unit );
glBindTexture( GL_TEXTURE_2D, getId() );
}
void Texture2D::loadImage( Image &image )
{
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
unsigned char depth = image.getDepth() / 8;
unsigned short format;
unsigned short components;
switch( depth )
{
case 1:
format = GL_LUMINANCE;
components = GL_LUMINANCE;
break;
case 3:
format = GL_BGR;
components = GL_RGB;
break;
case 4:
format = GL_BGRA;
components = GL_RGBA;
break;
default:
assert( false );
break;
}
glTexImage2D( GL_TEXTURE_2D,
0,
components,
image.getWidth(),
image.getHeight(),
0,
format,
GL_UNSIGNED_BYTE,
image.getBuffer() );
}