Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.cpp
- * TestEnvGlut2
- *
- * Created by Jos Timanta Tarigan on 8/5/10.
- * Copyright 2010 Linkoping University. All rights reserved.
- *
- */
- /*
- * main.cpp
- * TestEnvGlut
- *
- * Created by Jos Timanta Tarigan on 8/5/10.
- * Copyright 2010 Linkoping University. All rights reserved.
- *
- */
- #include <GLUT/glut.h>
- #include <FreeImage/FreeImage.h>
- #include <stdio.h> // for fopen, FILE & NULL
- #include <cstdlib>
- #include <iostream>
- #define PI 3.14159265
- int width = 100;
- int height = 100;
- int size = 10;
- GLuint texname = 0;
- ///Now the interesting code:
- void loadTexture(const char* textureFile){
- FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(textureFile,0);//Automatocally detects the format(from over 20 formats!)
- FIBITMAP* imagen = FreeImage_Load(formato, textureFile);
- FIBITMAP* temp = imagen;
- imagen = FreeImage_ConvertTo32Bits(imagen);
- FreeImage_Unload(temp);
- int w = FreeImage_GetWidth(imagen);
- int h = FreeImage_GetHeight(imagen);
- std::cout<<"The size of the image is: "<<textureFile<<" es "<<w<<"*"<<h<<std::endl; //Some debugging code
- GLubyte* textura = new GLubyte[4*w*h];
- char* pixeles = (char*)FreeImage_GetBits(imagen);
- //FreeImage loads in BGR format, so you need to swap some bytes(Or use GL_BGR).
- for(int j= 0; j<w*h; j++){
- textura[j*4+0]= pixeles[j*4+2];
- textura[j*4+1]= pixeles[j*4+1];
- textura[j*4+2]= pixeles[j*4+0];
- textura[j*4+3]= pixeles[j*4+3];
- //cout<<j<<": "<<textura[j*4+0]<<"**"<<textura[j*4+1]<<"**"<<textura[j*4+2]<<"**"<<textura[j*4+3]<<endl;
- }
- std::cout << "finish" << std::endl;
- //Now generate the OpenGL texture object
- std::cerr << "what?" << std::endl;
- glGenTextures(1, &texname);
- std::cerr << "asdf?" << std::endl;
- glBindTexture(GL_TEXTURE_2D, texname);
- std::cout << "wer?" << std::endl;
- glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, w, h, 0, GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)textura );
- std::cout << "is it?" << std::endl;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- GLenum huboError = glGetError();
- if(huboError){
- std::cout<<"There was an error loading the texture"<<std::endl;
- }
- }
- int main ()
- {
- loadTexture("2.bmp");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement