Adding a new Opengl2d3d.dll function
by Joe Rossi · in Torque Game Builder · 11/19/2005 (8:18 am) · 4 replies
Hello..
I'm (slowly..!) trying to load compressed .DDS files into Torque. I'm having trouble adding a function to Opengl2d3d.dll, namely glCompressedTexImage2D.
I don't need help coding the function but some insight on where/when it would load into Torque from the DLL. I tried a few things but it just won't "see" this function in DirectX mode. It's not super important since I can just use OGL but for the sake of completeness I'd like it to also work in DX mode.
I'm (slowly..!) trying to load compressed .DDS files into Torque. I'm having trouble adding a function to Opengl2d3d.dll, namely glCompressedTexImage2D.
I don't need help coding the function but some insight on where/when it would load into Torque from the DLL. I tried a few things but it just won't "see" this function in DirectX mode. It's not super important since I can just use OGL but for the sake of completeness I'd like it to also work in DX mode.
#2
If anyone has suggestions I'd like to hear them.
11/19/2005 (2:21 pm)
Hmm but in the DLL source it appears there are DX versions of every OpenGL call, I added another in with those. I made a simple "glCompressedTexImage2DARB" that will print "success" to the console, but it won't get that far. I tried to force load the d3d function when the engine fails to see the OGL extension (ie DX mode) but somehow it doesn't load it. I don't know what's going on so I'm taking shots in the dark at this.If anyone has suggestions I'd like to hear them.
#3
Now I can try the DirectX version, I think.
11/19/2005 (10:14 pm)
I see what I did! In winGL.cc I was calling qwglGetProcAddress when I shouldve used GPA_GL !Now I can try the DirectX version, I think.
#4
I'm no DX expert, but after some googling I arrived at this:
That's basically it besides setup code to set "fmt" to D3DX_SF_DXT5. My test case is a DXT5 compressed bullet image from the shooter demo. This shows no DX errors but also shows a white image. I'm sure it's a dumb mistake. If you see a problem plz clue me in.
Edit : If anyone is curious I gave up on all this... I'm an OpenGL man and just couldn't seem to figure it out. Plus the DXT compression isn't all that important, I guess...
11/21/2005 (12:39 pm)
Ok I lied I do need help coding the DirectX function. I'm at the point where I just need to create a texture from raw pixels. I just took the glTexImage2D code from the DLL and changed it so it can work for glCompressedTexImage2DARB. I'm no DX expert, but after some googling I arrived at this:
// How can I get pixels into a DDsurface?
DDSURFACEDESC2 ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_LINEARSIZE | DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
ddsd.dwHeight=height; ddsd.dwWidth=width;
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
ddsd.ddpfPixelFormat.dwFourCC = FOURCC_DXT5;
ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC ;
DWORD flags = D3DX_TEXTURE_NOMIPMAP;
// Create a texture object
HRESULT ddrval = D3DXCreateTexture(
g.m_d3ddev,
&flags,
(DWORD*)&width,
(DWORD*)&height,
&fmt,
NULL,
&ddsurf,
0);
if (ddrval != DD_OK) return ;
ddsurf->SetSurfaceDesc(&ddsd,0);
// Create texture from raw pixel data
ddrval = D3DXLoadTextureFromMemory(g.m_d3ddev,
ddsurf,
flags,
(DWORD*)pixels,
NULL,
fmt,
ddsd.lPitch ,
NULL,
D3DX_FT_LINEAR
);
if (ddrval != DD_OK) return ;That's basically it besides setup code to set "fmt" to D3DX_SF_DXT5. My test case is a DXT5 compressed bullet image from the shooter demo. This shows no DX errors but also shows a white image. I'm sure it's a dumb mistake. If you see a problem plz clue me in.
Edit : If anyone is curious I gave up on all this... I'm an OpenGL man and just couldn't seem to figure it out. Plus the DXT compression isn't all that important, I guess...
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft