need urgent help with textures

I’ve posted another topec but got no answer any help with this ehings would b appreiated !
Here’s the code !
{$M 1000000 8000000}
Uses tex,wingraph,crt,gl,glu,glut;
const poly1=1;
var poly:array[1…100]of GLuint;
img:texture;
texctrl:GLInt;
buf:PGLByte;
Procedure Init;
Begin
SetOpenGlMode(DirectOn);

GLMatrixMode(GL_PROJECTION);
GLBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
TexLoad(‘mop.tex’,img);
getmem(Buf,mxmy3);
Buf:=@img;

GLClearColor(0,0,0,0);
GLClear (GL_Color_Buffer_bit OR gl_dEPTH_buffer_bit);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);

GlEnable(GL_TEXTURE_2D);

GLGenTextures(1,@texctrl);
glBindTexture(GL_TEXTURE_2D,texctrl);

glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGB, mx, my, 0, GL_RGB, GL_byte, @buf);

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
GLTexEnvF(GL_Texture_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_Linear);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

end;
Procedure Draw;
Begin
GLNewList(poly1,GL_Compile);
GLENABLE(GL_TEXTURE_2D);
GLBegin(GL_POLYGON);
GLColor4f(1.0,1.0,1.0,1.0);
GLTexCoord2D(0,1);GLVertex3f(0.25,0.25,0.0);
GLTexCoord2D(1,1);GLVertex3f(0.75,0.25,0.0);
GLTexCoord2D(1,0);GLVertex3f(0.75,0.75,0.0);
GLTexCoord2D(0,0);GLVertex3f(0.25,0.75,0.0);
GLEnd();
GLEndList;
GLFlush();
GLDISABLE(GL_TEXTURE_2D);
end;
Begin
InitGraph(d8bit,m640x480,‘TEXTURE TEST 1’);
init;
draw;
GLCallList(Poly1);
updategraph(updatenow);
closegraph;
end;
end.

variable img is an [0…256,0…256,0…2]
It seems that I can’t make it work !
HELP ME PLS !
the result is at www.testimg.20m.com
10x !

I’m sorry for that I was really angry at that moment !
ok i’ll explain to you what is the problem !
the program should be very simple it should show an polygon with a texture ! but instead of showing it, shows only a few pixels !
an image is at http://www.testimg.20m.com/
test.bmp !
and by the way i’ve tried lots of methods but still doesen’t work and I don’t think of you like you are my personal debuggers I’ve been tryng to pot a texture ont that poly for 3 days and I can’t do it !
Sorry again !

I have last programmed in Pascal before too many years so I have forgot many things and I am not familiar with the units you are using so I may be entirely wrong in my gues.

Is polygon drawn correctly when texturing is not used? If it is i would assume that your texture initialization code is wrong and you are passing incorrect pointer into TexImage2D.

There are several things that are suspects to me:

getmem(Buf,mx*my*3);
Buf:=@img;

Here you are allocating memory yet you are on next line changing pointer to allocated memory to pointer to img variable. This looks to me as memory leak.

Buf:=@img

I do not know what a texture type is however because Pascal does have strong type checking i would assume that it is array of GLbyte or something like that so this can be correct and you are not taking pointer to somethng other than texture data.

glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGB, mx, my, 0, GL_RGB, GL_byte, @buf);

This looks to me as the cause of the trouble. TexImage2D expects as last parameter the pointer to data to load into texture however you use @buf which is pointer to pointer to data. Because of this instead of uploading texture image you are uploading some part of the memory in which buf variable is stored, try to remove the adress operator @ from this line.

One additional thing, while it is not bug i would expect that if you use glEnable inside display list, you will also add corresponding glDisable into that list which your Draw procedure does not.

from what i have found it is a good idea to include images of whats happening. i do aggree on the @buf, which is mentioned above. it took me a while to get texturing to work also.