Hi! Im trying to load a texture into an OpenGL scene.. The compiler doesn't give me any errors.. But when the program starts up I end up with windows error handler(Tells me to send a error report or ignore it).. However I use the default OpenGL code generated by CB.. Then I made some research about loading a texture into OpenGL without using SDL or something like that..I found this tutorial very helpful: http://www.nullterminator.net/gltexture.html . Hope you can give me some advice on how to fix this.. Here is my code:
Quote:Original post by Erik Rufelt Your data is RGB (3 bytes per pixel), but you tell OpenGL to use the data as GL_RGBA, which is 4 bytes per pixel. Try using GL_RGB.
Thanks! that did work.. Now there's another problem.. You see.. Now I've got a black window that doesn't display my texture at all.. Any advice on this? Do I need to declare a normal for the surface?
Edit: Yes, That's true.. But I still got this black window to deal with..
Quote:Original post by Erik Rufelt You need to add a glBegin(GL_QUADS) after your call to glRotatef. You never tell OpenGL that you begin drawing, so the glVertex2d are ignored.
Hehe, I saw it just before I read your last replay! Thanks man it all worked out now.. And thanks for the fast replay!
Hi. Can someone tell where i do mistake? I wrote the bmp class. And added bmp loader in class constructor. it should look like this http://3.ly/myqt but mine look this http://3.ly/ZdNZ
#include <string> #include <string.h> using namespace std;
class BMP { public:
BMP(string filess); ~BMP(); string filename; unsigned short int type; //2 /* Magic identifier */ unsigned int size; //4 /* File size in bytes */ unsigned short int reserved1; //2 unsigned short int reserved2; //2 unsigned int offset; //4 unsigned int header_size; //4 /* Header size in bytes */ int width; //4 int height; //4 /* Width and height of image */ unsigned short int planes; //2 /* Number of colour planes */ unsigned short int bits; //2 /* Bits per pixel */ unsigned int compression; //4 /* Compression type */ unsigned int imagesize; //4 /* Image size in bytes */ int xresolution; //4 int yresolution; //4 /* Pixels per meter */ unsigned int ncolours; //4 /* Number of colours */ unsigned int importantcolours;//4 /* Important colours */
long filesize; char c_array[53]; int BMP::chartoI(char i1, char i2, char i3,char i4); unsigned int BMP::chartoUI(char i1, char i2, char i3,char i4); unsigned short int BMP::chartoUSI (char i1,char i2); char * buffer; };
GLuint loadTexture() { GLuint textureId; glGenTextures(1, &textureId); //Make room for our texture glBindTexture(GL_TEXTURE_2D, textureId); //Tell OpenGL which texture to edit //Map the image to the texture glTexImage2D(GL_TEXTURE_2D, //Always GL_TEXTURE_2D 0, //0 for now GL_RGB, //Format OpenGL uses for image bmp.width, bmp.height, //Width and height 0, //The border of the image GL_RGB, //GL_RGB, because pixels are stored in RGB format GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE, because pixels are stored //as unsigned numbers bmp.buffer); //The actual pixel data //Returns the id of the texture
return textureId; }
GLuint _textureId = loadTexture();
//Called when a key is pressed void handleKeypress(unsigned char key, int x, int y) { switch (key) { case 27: //Escape key exit(0); } }
//Initializes 3D rendering void initRendering() { glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); //Enable color glClearColor(0.7f, 0.9f, 1.0f, 1.0f); //Change the background to sky blue }
//Called when the window is resized void handleResize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0); }
float _angle = 30.0f; float _cameraAngle = 0.0f;
//Draws the 3D scene void drawScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// The main body is from videotutorialsrock.com // You should take a look at this function GLuint "loadTexture()" becouse // the loader works fine (i think so :) ). }