Last active
December 28, 2015 10:09
-
-
Save rgoulter/7484560 to your computer and use it in GitHub Desktop.
IDK OpenGL TextureMap 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For Linux, NOT CROSS-PLATFORM | |
#include <GL/glut.h> | |
#include <SOIL/SOIL.h> | |
#include <iostream> | |
GLuint texImg; | |
int loadedImageWidth; | |
int loadedImageHeight; | |
unsigned char *loadedImageData; | |
void loadTexture() { | |
loadedImageData = | |
SOIL_load_image("image.bmp", &loadedImageWidth, &loadedImageHeight, 0, SOIL_LOAD_RGB); | |
if (loadedImageData == NULL) { | |
std::cout << "Unable to load image." << std::endl; | |
} | |
glActiveTexture(GL_TEXTURE0); | |
glGenTextures(1, &texImg); | |
glBindTexture(GL_TEXTURE_2D, texImg); | |
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_LINEAR); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
glTexImage2D(GL_TEXTURE_2D, | |
0, | |
GL_RGB, | |
loadedImageWidth, | |
loadedImageHeight, | |
0, | |
GL_RGB, | |
GL_UNSIGNED_BYTE, | |
loadedImageData); | |
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | |
int uniform_ImageTex = 1; | |
} | |
void display(void) { | |
glClearColor(0,0,0,0); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glEnable(GL_TEXTURE_2D); | |
// Draw a square | |
glBegin(GL_QUADS); | |
// glColor3f(1,0,0); | |
glTexCoord2f(0, 0); | |
glVertex2f(-0.5, +0.5); | |
glTexCoord2f(1, 0); | |
glVertex2f(+0.5, +0.5); | |
glTexCoord2f(1, 1); | |
glVertex2f(+0.5, -0.5); | |
glTexCoord2f(0, 1); | |
glVertex2f(-0.5, -0.5); | |
glEnd(); | |
glDisable(GL_TEXTURE_2D); | |
glutSwapBuffers(); | |
} | |
void reshape(int w, int h) { | |
} | |
int main(int argc, char **argv) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); | |
glutInitWindowPosition(200,200); | |
glutInitWindowSize(512,512); | |
glutCreateWindow("Hello OpenGL"); | |
glutDisplayFunc(display); | |
glutReshapeFunc(reshape); | |
loadTexture(); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some of this is fairly basic. I should probably read the Red Book?