Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <SDL_Image.h>
- void drawScene();
- void handleResize(int w,int h);
- GLuint TextureID;
- SDL_Surface *Image = IMG_Load("cb.png");
- void initRendering() {
- glDisable(GL_DEPTH_TEST);
- glGetError();
- glEnable(GL_NORMALIZE);
- glGetError();
- glEnable(GL_COLOR_MATERIAL);
- glGetError();
- glEnable(GL_TEXTURE_2D);
- glGetError();
- glEnable(GL_BLEND);
- glMatrixMode(GL_PROJECTION);
- glGetError();
- glLoadIdentity();
- glGetError();
- glClearColor(0,0,0,1);
- glGetError();
- }
- void Texture(SDL_Surface *Surface)
- {
- glGenTextures(1, &TextureID);
- glGetError();
- glBindTexture(GL_TEXTURE_2D, TextureID);
- glGetError();
- GLint Mode = GL_RGB;
- if(Surface->format->BytesPerPixel == 4) {
- Mode = GL_RGBA;
- }
- glGetError();
- glGetError();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glGetError();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glGetError();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexImage2D(GL_TEXTURE_2D, 0, Mode, Surface->w, Surface->h, 0, Mode, GL_UNSIGNED_BYTE, Surface->pixels);
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize(400, 400);
- glutCreateWindow("Textures - SLD & OpenGL");
- initRendering();
- Texture(Image);
- glutDisplayFunc(drawScene);
- //glutKeyboardFunc(handleKeypress);
- glutReshapeFunc(handleResize);
- glutMainLoop();
- return 0;
- }
- void handleResize(int w,int h)
- {
- glViewport (0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D (0, (GLdouble) w, 0, (GLdouble) h);
- }
- void drawScene() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glGetError();
- glMatrixMode(GL_MODELVIEW);
- glGetError();
- glLoadIdentity();
- glGetError();
- // For Ortho mode, of course
- int X = 150;
- int Y = 150;
- int Width = 100;
- int Height = 100;
- glBegin(GL_QUADS);
- glColor3f(1,1,1);
- glTexCoord2f(0, 0); glVertex3f(X, Y, 0);
- glTexCoord2f(1, 0); glVertex3f(X + Width, Y, 0);
- glTexCoord2f(1, 1); glVertex3f(X + Width, Y + Height, 0);
- glTexCoord2f(0, 1); glVertex3f(X, Y + Height, 0);
- glEnd();
- glutSwapBuffers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement