-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture.cpp
82 lines (67 loc) · 1.83 KB
/
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
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
/***********************************************
* $author: javery
* $date : 26 Nov 01
* $descp : texture management struct/routines.
* $path : C:\Program Files\Microsoft Visual Studio\MyProjects\KaosDemoEngine\texture.h
* $ver : 0.0.0
***********************************************/
#include <stdio.h>
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include "texture.h"
static k_word textureCount=0;
static void R_Tx_InitTexture( GLenum mmFilter , GLenum mxFilter , k_word textureRef )
{
glBindTexture( GL_TEXTURE_2D , textureRef );
glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , mmFilter );
glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , mxFilter );
}
k_word R_Tx_LoadTexture( char* sFileName )
{
AUX_RGBImageRec* texImage;
FILE* pTexFile = fopen( sFileName , "rb" );
if( pTexFile == NULL )
{
MessageBox( NULL , "Unable to load specified texture file","R_Tx_LoadTexture fault", MB_OK | MB_ICONEXCLAMATION );
PostQuitMessage( 0 );
return 0xFFFF;
}
else
{
texImage = auxDIBImageLoad( sFileName );
}
R_Tx_InitTexture( GL_LINEAR , GL_LINEAR , textureCount );
gluBuild2DMipmaps( GL_TEXTURE_2D,
3,
texImage->sizeX,
texImage->sizeY,
GL_RGB,
GL_UNSIGNED_BYTE,
texImage->data );
textureCount++;
return textureCount-1;
}
void R_Tx_UseTexture( k_word texIndex )
{
glBindTexture( GL_TEXTURE_2D , texIndex );
}
//
// Builds a texture from the passed byte buffer
//
k_word R_Tx_BuildTexture( k_word xDimen , k_word yDimen , k_byte depth , void* byteBuffer )
{
R_Tx_InitTexture( GL_LINEAR , GL_LINEAR , textureCount );
glTexImage2D( GL_TEXTURE_2D ,
0 ,
3 ,
xDimen,
yDimen,
0,
GL_COLOR_INDEX,
GL_BYTE,
byteBuffer );
textureCount++;
return textureCount-1;
}