[ pera89 @ 05.07.2007. 06:21 ] @
Pokusavam da ucitam BMP teksturu sa FreePascal-om. Prvo sam na BMP fajlu odstranio prvih 54 bajta jer su to informacije o dimenzijama slike itd.(koliko ja znam, ispravite me ako gresim). I onda sam zamenio mesta nekim bajtovima da bi format bio RGB a ne BGR kao u bmp formatu(Naravno napisao sam program koji ce to da uradi, nisam rucno menjao mesta). Ovaj izmenjen fajl sam nazvao 'test.tex'. Rezolucija teksture je 64x64. Napisao sam prost program koji koristi OpenGL i treba da ucita ovu teksturu i da je mapira na jednom kvadratu, medjutim umesto teksture na kvadratu vidim samo belu boju. Evo koda i molim vas kazite mi u cemu sam pogresio: {$mode objfpc} program ogltest; uses GL, GLU, GLUT; var f:file; data:pointer; textureID:GLuint; procedure DrawIt; begin glBegin(Gl_Quads); glTexCoord2f(0,0); glVertex2f(0,0); glTexCoord2f(1,0); glVertex2f(5,0); glTexCoord2f(1,1); glVertex2f(5,5); glTexCoord2f(0,1); glVertex2f(0,5); glEnd; end; procedure DisplayWindow; cdecl; begin glClearColor(0, 0, 0.2, 1); glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT); DrawIt; glutSwapBuffers; end; procedure OnTimer(value: Integer); cdecl; begin glutPostRedisplay; glutTimerFunc(20, @OnTimer, 0); end; procedure keyb(xx1:byte;xx2,xx3:longint); cdecl; begin if xx1=27 then halt(0); end; begin GetMem(data,12288); //64*64*3 assign(f,'test.tex'); reset(f,1); BlockRead(f,data^,12288); close(f); glEnable(GL_TEXTURE_2D); glGenTextures(1,@textureID); glBindTexture(GL_Texture_2D, TextureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 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); glTexImage2D(GL_TEXTURE_2D,0,3,64,64,1,GL_RGB,GL_UNSIGNED_BYTE,data); glBindTexture(GL_Texture_2D, TextureID); glutInit(@argc, argv); glutInitDisplayMode(GLUT_RGB or GLUT_DOUBLE or GLUT_DEPTH); glutInitWindowSize(640,480); glutCreateWindow('!!!'); glutDisplayFunc(@DisplayWindow); glutKeyboardFunc(@keyb); glutTimerFunc(20, @OnTimer, 0); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glClearDepth(1.0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glMatrixMode(GL_PROJECTION); glLoadIdentity; gluPerspective(90, 1.25, 5, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity; glTranslatef(0, 0, -10); glShadeModel(GL_SMOOTH); glutMainLoop; end. P.S. Pocetnik sam u OpenGL programiranju, tako da ovaj kod mozda sadrzi pocetnicke greske. |