how to use this code ??
-
i have this code to load a bmp picture. but i don't know how to use it.!!!
#include "stdafx.h" #include "glaux.h" #include "glut.h"
GLuint texture[6];
int LoadGLTextures() { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage[0]=LoadBMP("apple.bmp")) { Status=TRUE; // Set The Status To TRUE glGenTextures(3, &texture[0]); // Create Three Textures // Create Nearest Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW ) glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create Linear Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[1]); 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, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX,TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE,TextureImage[0]->data); // ( NEW ) if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } } return Status; } //----------------------------------------------------------------------------- AUX_RGBImageRec
-
i have this code to load a bmp picture. but i don't know how to use it.!!!
#include "stdafx.h" #include "glaux.h" #include "glut.h"
GLuint texture[6];
int LoadGLTextures() { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage[0]=LoadBMP("apple.bmp")) { Status=TRUE; // Set The Status To TRUE glGenTextures(3, &texture[0]); // Create Three Textures // Create Nearest Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW ) glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create Linear Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[1]); 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, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // ( NEW ) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX,TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE,TextureImage[0]->data); // ( NEW ) if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } } return Status; } //----------------------------------------------------------------------------- AUX_RGBImageRec
What you need to do is to get an idea on what to do to use an image as texture with OpenGL by reading the code you posted. Then you can incorporate that into your project. The basic idea is not that complicated. If the piece of code you provided is part of a sample project, you can compile and run the project to see how it works. Hope this helps. Happy programming!
-
What you need to do is to get an idea on what to do to use an image as texture with OpenGL by reading the code you posted. Then you can incorporate that into your project. The basic idea is not that complicated. If the piece of code you provided is part of a sample project, you can compile and run the project to see how it works. Hope this helps. Happy programming!
-
I think the code you've provided is already an example and "simple" enough (saw the inline comments?)
“Follow your bliss.” – Joseph Campbell
-
I think the code you've provided is already an example and "simple" enough (saw the inline comments?)
“Follow your bliss.” – Joseph Campbell
but i put apple.bmp in the same folder with main code, write int main() to use it. then it did not work.
int main(int argc, char* argv[])
{glutInit(&argc, argv); glutInitDisplayMode(GLUT\_DOUBLE | GLUT\_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition(0, 0); glutCreateWindow("Hello OpenGL!"); OnInit(); glutDisplayFunc(OnDraw); glutReshapeFunc(OnSize); glutIdleFunc(OnIdle); glutKeyboardFunc(OnKey); //--------------------------- glutMouseFunc(OnMouse); glutSpecialFunc(OnKeySpecial); LoadGLTextures(); //--------------------------- glutMainLoop(); return 0;
}
-
but i put apple.bmp in the same folder with main code, write int main() to use it. then it did not work.
int main(int argc, char* argv[])
{glutInit(&argc, argv); glutInitDisplayMode(GLUT\_DOUBLE | GLUT\_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition(0, 0); glutCreateWindow("Hello OpenGL!"); OnInit(); glutDisplayFunc(OnDraw); glutReshapeFunc(OnSize); glutIdleFunc(OnIdle); glutKeyboardFunc(OnKey); //--------------------------- glutMouseFunc(OnMouse); glutSpecialFunc(OnKeySpecial); LoadGLTextures(); //--------------------------- glutMainLoop(); return 0;
}
Did you debug it to see if it could not find the file or bitmap failed to load? If you're using Visual Studio, I think you need to put the bitmap in the folder with the executable, not the source so Release or Debug.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
-
Did you debug it to see if it could not find the file or bitmap failed to load? If you're using Visual Studio, I think you need to put the bitmap in the folder with the executable, not the source so Release or Debug.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
-
this is my project. draw B-spline by De Boor method, and use it to take boundary of bmp picture. http://www.mediafire.com/?4m2jrmg3lyv[^]
-
That's it? Where did the executable file end up?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
-
the problem is: i have this code to load bmp picture, but i don't know how to use.
int LoadGLTextures();
i only need to load bmp picture.