🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using textures from 3d exploration generated code

Started by
0 comments, last by AlanW 24 years ago
I made a cube in Poser 3, then applied a texture to it, saved it as a .3ds file, and finally used 3d exploration to convert it to opengl c++ code. The problem is that when I run it, it gives me an access violation error, and then points to the line with glTexCoord2f() Heres the code (i tried to cut down as much as possible): //included files here GLuint texture[1]; //prototypes here //a lot of lines of code just #s which describe the object here void GenerateObjects(void) { int i; int j; GLint lid=glGenLists(1); glNewList(lid, GL_COMPILE); glBegin (GL_TRIANGLES); for(i=0;i[j]; GLint ni=face_indicies[j+3]; GLint ti=face_indicies[j+6]; glBindTexture(GL_TEXTURE_2D, texture[0]); glTexCoord2f(textures[ti][0],textures[ti][1]); glVertex3f(verticies[vi][0],verticies[vi][1],verticies[vi][2]); } } glEnd (); glEndList(); } void LoadTextures(void) { AUX_RGBImageRec *TextureImage[1]; memset(TextureImage, 0, sizeof(void *)*1); if(TextureImage[0]=LoadBMP("Texture1.bmp")) { glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { exit(0); } if(TextureImage[0]) { if(TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } } //extra code for setting up lights, enabling stuff, etc. thats not important (i enabled GL_TEXTURE_2D by the way) void renderscene(void) { glClear( GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT ); glColor3f(1.0, 1.0, 1.0); GenerateObjects(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE / GLUT_RGB / GLUT_DEPTH ); glutInitWindowPosition( 100,100 ); glutInitWindowSize( 500,500 ); glutCreateWindow("Testing textures with generated code"); initOpenGL(); glutReshapeFunc(ChangeSize); glutDisplayFunc(renderscene); glutMainLoop(); return 0; } Sorry for this huge post but i''m all out of ideas here and I don''t know what to do. I''m not sure if i''m going about this the completely wrong way either, but does anyone know what the problem is? Also, the function LoadBMP() is in an included header, and it works because i have used it before…so thats not the problem. Thanks everyone! </i> -Alan W. "Adventure, excitement, a Jedi craves not these things." - Yoda =)
-Alan W."Adventure, excitement, a Jedi craves not these things." - Yoda=)
Advertisement
Hi,

an access violation can occured when you want to access outside the size of an array (hmm..not easy to describe this in english)
ex:

myFunction(){
int array[2];
...
array[3]=10; //access violation
...
}

So check the value of "ti" in :
glTexCoord2f(textures[ti][0],textures[ti][1]);

Another thing (not related to your problem):
you cannot bind texture(glBindTexture) between glBegin and glEnd.
Just call the function before glBegin.
hope that help!

lunasol

This topic is closed to new replies.

Advertisement