summaryrefslogtreecommitdiff
path: root/glgfx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'glgfx.cpp')
-rw-r--r--glgfx.cpp61
1 files changed, 57 insertions, 4 deletions
diff --git a/glgfx.cpp b/glgfx.cpp
index 9393d66..bed50d4 100644
--- a/glgfx.cpp
+++ b/glgfx.cpp
@@ -3,6 +3,7 @@
//buffer data is the data you bind to opengl
GLuint vbhandler; //vertex buffer handle
GLuint ebhandler;
+GLuint texhandlers[2];
//handlers for the perspective transforms
GLint projhandler;
GLint tranhandler;
@@ -41,7 +42,7 @@ int initglgfx() {
glGenBuffers(1, &glnum);
printf("%u\n",glnum);
//vertex data load of the box model
- float vertexdata[] = {
+/* float vertexdata[] = {
-0.500000,0.500000,-0.500000, 0.000000,0.000000,-1.000000, 0.500000,0.500000,-0.500000, 0.000000,0.000000,-1.000000, -0.500000,-0.500000,-0.500000, 0.000000,0.000000,-1.000000,
-0.500000,-0.500000,-0.500000, 0.000000,0.000000,-1.000000, 0.500000,0.500000,-0.500000, 0.000000,0.000000,-1.000000, 0.500000,-0.500000,-0.500000, 0.000000,0.000000,-1.000000,
0.500000,0.500000,-0.500000, 1.000000,0.000000,0.000000, 0.500000,0.500000,0.500000, 1.000000,0.000000,0.000000, 0.500000,-0.500000,-0.500000, 1.000000,0.000000,0.000000,
@@ -54,6 +55,20 @@ int initglgfx() {
0.500000,-0.500000,-0.500000, 0.000000,-1.000000,0.000000, 0.500000,-0.500000,0.500000, 0.000000,-1.000000,0.000000, -0.500000,-0.500000,-0.500000, 0.000000,-1.000000,0.000000,
-0.500000,0.500000,-0.500000, 0.000000,1.000000,0.000000, -0.500000,0.500000,0.500000, 0.000000,1.000000,0.000000, 0.500000,0.500000,0.500000, 0.000000,1.000000,0.000000,
0.500000,0.500000,0.500000, 0.000000,1.000000,0.000000, 0.500000,0.500000,-0.500000, 0.000000,1.000000,0.000000, -0.500000,0.500000,-0.500000, 0.000000,1.000000,0.000000,
+ };*/
+ float vertexdata[] = {
+-0.500000,0.500000,-0.500000, 0.000000,0.000000,-1.000000, 0.000000,1.000000,0.000000, 0.500000,0.500000,-0.500000, 0.000000,0.000000,-1.000000, 1.000000,1.000000,0.000000, -0.500000,-0.500000,-0.500000, 0.000000,0.000000,-1.000000, 0.000000,0.000000,0.000000,
+-0.500000,-0.500000,-0.500000, 0.000000,0.000000,-1.000000, 0.000000,0.000000,0.000000, 0.500000,0.500000,-0.500000, 0.000000,0.000000,-1.000000, 1.000000,1.000000,0.000000, 0.500000,-0.500000,-0.500000, 0.000000,0.000000,-1.000000, 1.000000,0.000000,0.000000,
+0.500000,0.500000,-0.500000, 1.000000,0.000000,0.000000, 0.000000,1.000000,0.000000, 0.500000,0.500000,0.500000, 1.000000,0.000000,0.000000, 1.000000,1.000000,0.000000, 0.500000,-0.500000,-0.500000, 1.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,
+0.500000,-0.500000,-0.500000, 1.000000,0.000000,0.000000, 0.000000,0.000000,0.000000, 0.500000,0.500000,0.500000, 1.000000,0.000000,0.000000, 1.000000,1.000000,0.000000, 0.500000,-0.500000,0.500000, 1.000000,0.000000,0.000000, 1.000000,0.000000,0.000000,
+0.500000,0.500000,0.500000, 0.000000,0.000000,1.000000, 0.000000,1.000000,0.000000, -0.500000,0.500000,0.500000, 0.000000,0.000000,1.000000, 1.000000,1.000000,0.000000, 0.500000,-0.500000,0.500000, 0.000000,0.000000,1.000000, 0.000000,0.000000,0.000000,
+-0.500000,0.500000,0.500000, 0.000000,0.000000,1.000000, 1.000000,1.000000,0.000000, -0.500000,-0.500000,0.500000, 0.000000,0.000000,1.000000, 1.000000,0.000000,0.000000, 0.500000,-0.500000,0.500000, 0.000000,0.000000,1.000000, 0.000000,0.000000,0.000000,
+-0.500000,0.500000,0.500000, -1.000000,0.000000,0.000000, 0.000000,1.000000,0.000000, -0.500000,0.500000,-0.500000, -1.000000,0.000000,0.000000, 1.000000,1.000000,0.000000, -0.500000,-0.500000,0.500000, -1.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,
+-0.500000,0.500000,-0.500000, -1.000000,0.000000,0.000000, 1.000000,1.000000,0.000000, -0.500000,-0.500000,-0.500000, -1.000000,0.000000,0.000000, 1.000000,0.000000,0.000000, -0.500000,-0.500000,0.500000, -1.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,
+-0.500000,-0.500000,-0.500000, 0.000000,-1.000000,0.000000, 0.000000,0.000000,0.000000, 0.500000,-0.500000,0.500000, 0.000000,-1.000000,0.000000, 1.000000,1.000000,0.000000, -0.500000,-0.500000,0.500000, 0.000000,-1.000000,0.000000, 0.000000,1.000000,0.000000,
+0.500000,-0.500000,-0.500000, 0.000000,-1.000000,0.000000, 1.000000,0.000000,0.000000, 0.500000,-0.500000,0.500000, 0.000000,-1.000000,0.000000, 1.000000,1.000000,0.000000, -0.500000,-0.500000,-0.500000, 0.000000,-1.000000,0.000000, 0.000000,0.000000,0.000000,
+-0.500000,0.500000,-0.500000, 0.000000,1.000000,0.000000, 0.000000,0.000000,0.000000, -0.500000,0.500000,0.500000, 0.000000,1.000000,0.000000, 1.000000,0.000000,0.000000, 0.500000,0.500000,0.500000, 0.000000,1.000000,0.000000, 1.000000,1.000000,0.000000,
+0.500000,0.500000,0.500000, 0.000000,1.000000,0.000000, 1.000000,1.000000,0.000000, 0.500000,0.500000,-0.500000, 0.000000,1.000000,0.000000, 0.000000,1.000000,0.000000, -0.500000,0.500000,-0.500000, 0.000000,1.000000,0.000000, 0.000000,0.000000,0.000000,
};
/* float vertexdata[] = {
-0.5, 0.5, -.5, // x y z
@@ -106,9 +121,18 @@ int initglgfx() {
glGenBuffers(1,&ebhandler);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ebhandler);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elementdata), elementdata, GL_DYNAMIC_DRAW);
+ //loads textures
+ glGenTextures(2, texhandlers);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texhandlers[0]);
+ glgfxloadtexture("textures/tex.bmp");
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, texhandlers[1]);
+ glgfxloadtexture("textures/elev.bmp");
//loads the shaders
genshaders();
-
+ glUniform1i(glGetUniformLocation(shaderprogramhandle, "tex"), 0);
+ glUniform1i(glGetUniformLocation(shaderprogramhandle, "elev"), 1);
}
//loads shaders and models
int genshaders() {
@@ -166,14 +190,20 @@ int genshaders() {
pos = glGetAttribLocation(shaderprogramhandle, "position");
//the actual atribute, number of values, type, whether they need to be normalied to -1 1,
//number of bytes between values, offset from beginning in bytes
- glVertexAttribPointer(pos, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), 0);
+ glVertexAttribPointer(pos, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 0);
glEnableVertexAttribArray(pos);
GLint vnorm;
vnorm = glGetAttribLocation(shaderprogramhandle, "vnormal");
//the actual atribute, number of values, type, whether they need to be normalied to -1 1,
//number of bytes between values, offset from beginning in bytes
- glVertexAttribPointer(vnorm, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *) (3 * sizeof(float)) );
+ glVertexAttribPointer(vnorm, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void *) (3 * sizeof(float)) );
glEnableVertexAttribArray(vnorm);
+ GLint texcoord;
+ texcoord = glGetAttribLocation(shaderprogramhandle, "texcoord");
+ //the actual atribute, number of values, type, whether they need to be normalied to -1 1,
+ //number of bytes between values, offset from beginning in bytes
+ glVertexAttribPointer(texcoord, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void *) (6 * sizeof(float)) );
+ glEnableVertexAttribArray(texcoord);
//getting uniform handler
projhandler = glGetUniformLocation(shaderprogramhandle, "proj");
camhandler = glGetUniformLocation(shaderprogramhandle, "cam");
@@ -257,3 +287,26 @@ int clearglgfx() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return 0;
}
+int glgfxloadtexture (const char * file) {
+ SDL_Surface * tsp;
+ tsp = SDL_LoadBMP(file);
+ //we're just gonna forget their handlers since loading texture data is a
+ //one time thing anyways
+ //texture to bind to, detail,format,
+ printf("num of pixels\n %d \n", tsp->format->BitsPerPixel); //32 bits per pixel
+ printf("Rmask\n %04x \n", tsp->format->Rmask); // ff000000
+ printf("Gmask\n %04x \n", tsp->format->Gmask); // 00ff0000
+ printf("Bmask\n %04x \n", tsp->format->Bmask); // 0000ff00
+ printf("Amask\n %04x \n", tsp->format->Amask); // 000000ff
+ tsp = SDL_ConvertSurfaceFormat(tsp, SDL_PIXELFORMAT_RGBA32, 0);
+ //int w;
+ //int h;
+ //int c;
+ //unsigned char * data =SOIL_load_image(file, &w, &h,&c, SOIL_LOAD_BMP);
+ //printf("w%d\n",h);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tsp->w, tsp->h, 0, GL_RGBA, GL_UNSIGNED_BYTE,(void *) tsp->pixels);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ //drawimg(0,0,100,100,file);
+ SDL_FreeSurface(tsp);
+}