Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture on pyramid

Started by redrum237 Feb 23, 2009 at 9:09 AM 0 replies 450+ views
Original Post
redrum237
redrum237
Hi. I have source code from a website, where it states how to apply a texture to a pyramid. I am unsure of how to do this, and this is the code i have so far: // // Implement basic texture IO functionality // #include "textures.h" // Load a bitmap and setup as an OpenGL texture. Return the textureID OpenGL uses // to reference the texture! GLuint loadTexture(LPTSTR szFileName) { HBITMAP hBMP; BITMAP BMP; GLuint newTexture = 0; // 1. Load bitmap image hBMP = (HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE ); if (!hBMP) return 0; // 2. Get bitmap object GetObject(hBMP, sizeof(BMP), &BMP); // 3. Setup image as an OpenGL texture glGenTextures(1, &newTexture); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // make the current texture glBindTexture(GL_TEXTURE_2D, newTexture); // Setup texture properties glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // use linear filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // 4. Dispose of unwanted bitmap object DeleteObject(hBMP); // 5. Finally return to calling function the texture ID used to reference the texture image in OpenGL. return newTexture; } i have an image file called texture1.bmp, but am unsure where i need to include it. thanks
Lord_Evil
Lord_Evil
So you have your image and can load it with your function. Great.

What you need is to store the id, create geometry (with texture coordinates), bind the texture and draw your geometry. Maybe you want to have a look at the many OpenGL tutorials out there, e.g. NeHe (although a bit outdated).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.