-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.c
More file actions
67 lines (55 loc) · 1.61 KB
/
Copy pathtexture.c
File metadata and controls
67 lines (55 loc) · 1.61 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
61
62
63
64
65
66
67
/*
* Final Program, CMPS 160, Fall 1999
* Ben Gertzfield <ben@cse.ucsc.edu>
*
* This program is released under the GNU GPL, version 2 or later.
*/
/* Texturing routines */
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <gtk/gtk.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include "prog.h"
#include "rgb.h"
static GLuint textures[MAX_TEXTURES];
void gkos_init_textures(void)
{
glGenTextures(MAX_TEXTURES, textures);
}
GLuint gkos_new_texture(gchar *filename, int dim)
{
RGBImageRec *texture;
GLuint texture_id;
texture_id = textures[0];
texture = rgbImageLoad((char *) filename);
if (texture == NULL || texture->data == NULL) {
fprintf(stderr, "Error reading texture from file %s. No texture will be used.\n",
filename);
return 0;
}
if (dim == 2) {
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->sizeX, texture->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, texture->data);
} else if (dim == 1) {
glBindTexture(GL_TEXTURE_1D, texture_id);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, texture->sizeX, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->data);
}
return texture_id;
}
// Local variables:
// c-file-style:"cc-mode"
// End: