access the image directly...
D3DFunc is a little plugin originally for DBPro that allowed fast anti-aliased text and image manipulation, through using GDK to access directX directly, you can get the source from the author's website(look in Program Announcements for the thread re D3DFunc)
If you search these forums for the subject you should find a few methods, I know lilith, a regular forums user here, has an image manip class that she has posted somewhere around...
Ill post on here that I have lying around, I didnt write it and I dont remember who did, but if you recognise your code, cheers
ExtendedImage.h:
#ifndef _EXTENDEDIMAGEGPU_H_
#define _EXTENDEDIMAGEGPU_H_
struct tVert {
float x, y, z;
DWORD colour;
};
struct tVertW {
float x, y, z, w;
DWORD colour;
};
void SetupExtendedImage_GPU();
void EnableZ_GPU(bool bEnabled);
void ClearImage(int nDestination, int nRed, int nGreen, int nBlue);
void DrawImageLine2D_GPU(int nDestination, int fX1, int fY1, int fX2, int fY2, DWORD nColourStart, DWORD nColourEnd);
void StartNew2dImageLineBatch();
void AddVertexTo2dLineBatch_GPU(float x, float y, float z, DWORD c) ;
void Add2dLineToImageBatch_GPU(int x, int y, int x2, int y2, DWORD nColourStart, DWORD nColourEnd);
void Draw2dLineImageBatch_GPU(int nDestination);
void StartNew2dImageTriangleBatch();
void AddVertexTo2dTriangleBatch_GPU(float x, float y, float z, DWORD c);
void Add2dTriangleToImageBatch_GPU(int x, int y, int x2, int y2, int x3, int y3, DWORD nColourPoint1, DWORD nColourPoint2, DWORD nColourPoint3);
void Draw2dTriangleImageBatch_GPU(int nDestination);
#endif
ExtendedImage.cpp:
#include "DarkGDK.h"
#include "d3d9.h"
#include "globstruct.h"
#include "ExtendedImageGPU.h"
IDirect3DDevice9* dbDxDevice = NULL;
HRESULT hLastErr;
int nZEnable = 0;
tVert aLine[2];
tVertW aLineW[2];
tVertW aLineBatch[2000];
tVertW aTriangleBatch[4000];
unsigned int nCurrentLineVert = 0;
unsigned int nCurrentTriVert = 0;
void SetupExtendedImage_GPU() {
if (dbDxDevice == NULL) {
dbDxDevice = dbGetDirect3DDevice();
}
}
void EnableZ_GPU(bool bEnabled) {
if (bEnabled) {
nZEnable = 1;
} else {
nZEnable = 0;
}
}
void StartNew2dImageLineBatch() {
nCurrentLineVert = 0;
}
void AddVertexTo2dLineBatch_GPU(float x, float y, float z, DWORD c) {
aLineBatch[nCurrentLineVert].x = x;
aLineBatch[nCurrentLineVert].y = y;
aLineBatch[nCurrentLineVert].z = z;
aLineBatch[nCurrentLineVert].w = 1.0f;
aLineBatch[nCurrentLineVert].colour = c;
nCurrentLineVert++;
}
void Add2dLineToImageBatch_GPU(int x, int y, int x2, int y2, DWORD nColourStart, DWORD nColourEnd) {
AddVertexTo2dLineBatch_GPU(x, y, 1.0f, nColourStart);
AddVertexTo2dLineBatch_GPU(x2, y2, 1.0f, nColourEnd);
}
void Draw2dLineImageBatch_GPU(int nDestination) {
LPDIRECT3DSURFACE9 destSurface;
LPDIRECT3DSURFACE9 originalRenderTarget;
dbGetImagePointer(nDestination)->GetSurfaceLevel(0, &destSurface);
dbDxDevice->GetRenderTarget(0, &originalRenderTarget);
dbDxDevice->SetRenderTarget(0, destSurface);
dbDxDevice->SetTexture(0, NULL);
dbDxDevice->SetTexture(1, NULL);
dbDxDevice->SetVertexShader(NULL);
dbDxDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
dbDxDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
dbDxDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
dbDxDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
dbDxDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
dbDxDevice->DrawPrimitiveUP(D3DPT_LINELIST, nCurrentLineVert / 2, aLineBatch, sizeof(tVertW));
hLastErr = dbDxDevice->SetRenderTarget(0, originalRenderTarget);
}
void StartNew2dImageTriangleBatch() {
nCurrentTriVert = 0;
}
void AddVertexTo2dTriangleBatch_GPU(float x, float y, float z, DWORD c) {
aTriangleBatch[nCurrentTriVert].x = x;
aTriangleBatch[nCurrentTriVert].y = y;
aTriangleBatch[nCurrentTriVert].z = z;
aTriangleBatch[nCurrentTriVert].w = 1.0f;
aTriangleBatch[nCurrentTriVert].colour = c;
nCurrentTriVert++;
}
void Add2dTriangleToImageBatch_GPU(int x, int y, int x2, int y2, int x3, int y3, DWORD nColourPoint1, DWORD nColourPoint2, DWORD nColourPoint3) {
AddVertexTo2dTriangleBatch_GPU(x, y, 1.0f, nColourPoint1);
AddVertexTo2dTriangleBatch_GPU(x2, y2, 1.0f, nColourPoint2);
AddVertexTo2dTriangleBatch_GPU(x3, y3, 1.0f, nColourPoint3);
}
void Draw2dTriangleImageBatch_GPU(int nDestination) {
LPDIRECT3DSURFACE9 destSurface;
LPDIRECT3DSURFACE9 originalRenderTarget;
dbGetImagePointer(nDestination)->GetSurfaceLevel(0, &destSurface);
dbDxDevice->GetRenderTarget(0, &originalRenderTarget);
dbDxDevice->SetRenderTarget(0, destSurface);
dbDxDevice->SetTexture(0, NULL);
dbDxDevice->SetTexture(1, NULL);
dbDxDevice->SetVertexShader(NULL);
dbDxDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
dbDxDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
dbDxDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
dbDxDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
dbDxDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
dbDxDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, nCurrentTriVert / 3, aTriangleBatch, sizeof(tVertW));
hLastErr = dbDxDevice->SetRenderTarget(0, originalRenderTarget);
}
void ClearImage(int nDestination, int nRed, int nGreen, int nBlue) {
LPDIRECT3DSURFACE9 destSurface;
LPDIRECT3DSURFACE9 originalRenderTarget;
dbGetImagePointer(nDestination)->GetSurfaceLevel(0, &destSurface);
hLastErr = dbDxDevice->GetRenderTarget(0, &originalRenderTarget);
dbDxDevice->SetRenderTarget(0, destSurface);
dbDxDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE((float)nRed / 255.0f, (float)nGreen / 255.0f, (float)nBlue / 255.0f, 1.0f), 1.0f, 0);
dbDxDevice->SetRenderTarget(0, originalRenderTarget);
}
void DrawImageLine2D_GPU(int nDestination, int fX1, int fY1, int fX2, int fY2, DWORD nColourStart, DWORD nColourEnd) {
LPDIRECT3DSURFACE9 destSurface;
LPDIRECT3DSURFACE9 originalRenderTarget;
aLineW[0].x = fX1;
aLineW[0].y = fY1;
aLineW[0].z = 1.0f;
aLineW[0].w = 1.0f;
aLineW[0].colour = nColourStart;
aLineW[1].x = fX2;
aLineW[1].y = fY2;
aLineW[1].z = 1.0f;
aLineW[1].w = 1.0f;
aLineW[1].colour = nColourEnd;
dbGetImagePointer(nDestination)->GetSurfaceLevel(0, &destSurface);
dbDxDevice->GetRenderTarget(0, &originalRenderTarget);
dbDxDevice->SetRenderTarget(0, destSurface);
dbDxDevice->SetTexture(0, NULL);
dbDxDevice->SetTexture(1, NULL);
dbDxDevice->SetVertexShader(NULL);
dbDxDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
dbDxDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
dbDxDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
dbDxDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
dbDxDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
dbDxDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, aLineW, sizeof(tVertW));
hLastErr = dbDxDevice->SetRenderTarget(0, originalRenderTarget);
}
void DrawFilledTriangleBatch_GPU(int Dest) {
LPDIRECT3DSURFACE9 destSurface;
dbGetImagePointer(Dest)->GetSurfaceLevel(0, &destSurface);
LPDIRECT3DSURFACE9 originalRenderTarget;
hLastErr = dbDxDevice->GetRenderTarget(0, &originalRenderTarget);
hLastErr = dbDxDevice->SetRenderTarget(0, destSurface);
hLastErr = dbDxDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, 0);
hLastErr = dbDxDevice->SetRenderTarget(0, originalRenderTarget);
//tmpTexture->Release();
}
Usage Example.cpp:
void CVisualisation::VisBasic(CAudio *cAudioSystem) {
// DrawBox(nImageID, 0, 0, nTexWidth, nTexHeight, dbRgb(0, 0, 0));
ClearImage(nImageID, 0, 0, 0);
StartNew2dImageLineBatch();
DWORD dwCol1, dwCol2;
float r, g, b;
if (nVisColR == 0 && nVisColG == 0 && nVisColB == 0) {
int c = Rand2(80, 150);
dwCol1 = dbRgb(c, c, c);
if (c + 80 > 255) {
dwCol2 = dbRgb(255, 255, 255);
} else {
dwCol2 = dbRgb(c + 80, c + 80, c + 80);
}
} else {
r = Rand2(0, nVisColR);
g = Rand2(0, nVisColG);
b = Rand2(0, nVisColB);
dwCol1 = dbRgb(r, g, b);
if (r + 80 > 255) { r = 255; } else { r += 80; }
if (g + 80 > 255) { g = 255; } else { g += 80; }
if (b + 80 > 255) { b = 255; } else { b += 80; }
dwCol2 = dbRgb(r, g, b);
}
for (int n = 0; n <= SPECTRUM_SIZE / 2; n++) {
Add2dLineToImageBatch_GPU(n, (int)(nTexHeight * 0.5f) - (int)(cAudioSystem->GetSpectrumValue(n) * (int)(nTexHeight * 0.5f)), n, (int)(nTexHeight * 0.5f) + (int)((cAudioSystem->GetSpectrumValue(n) + 0.02f) * (int)(nTexHeight * 0.5f)), dwCol2, dwCol1);
Add2dLineToImageBatch_GPU(SPECTRUM_SIZE - n, (int)(nTexHeight * 0.5f) - (int)(cAudioSystem->GetSpectrumValue(n) * (int)(nTexHeight * 0.5f)), SPECTRUM_SIZE - n, (int)(nTexHeight * 0.5f) + (int)((cAudioSystem->GetSpectrumValue(n) + 0.02f) * (int)(nTexHeight * 0.5f)), dwCol1, dwCol2);
Add2dLineToImageBatch_GPU((int)(nTexWidth * 0.5f) - (int)(cAudioSystem->GetSpectrumValue(n) * (int)(nTexWidth * 0.5f)), n, (int)(nTexWidth * 0.5f) + (int)((cAudioSystem->GetSpectrumValue(n) + 0.02f) * (int)(nTexWidth * 0.5f)), n, dwCol2, dwCol1);
Add2dLineToImageBatch_GPU((int)(nTexWidth * 0.5f) - (int)(cAudioSystem->GetSpectrumValue(n) * (int)(nTexWidth * 0.5f)), SPECTRUM_SIZE - n, (int)(nTexWidth * 0.5f) + (int)((cAudioSystem->GetSpectrumValue(n) + 0.02f) * (int)(nTexWidth * 0.5f)), SPECTRUM_SIZE - n, dwCol1, dwCol2);
}
Draw2dLineImageBatch_GPU(nImageID);
}
Just to re-iterate, I didnt write the above code, I downloaded it from these forums somewhere(although to my shame, I cant remember who the author is, and I apologise for that... if this is your code feel free to mention it)
The above should show you basically how you can access an image directly using GDK.
EDIT : After thinking about it for a bit, there is also a much easier, albiet slower way of gettnig that kind of data into GDK, using an image as an example, you would read your data into data structure of somekind, storing the relevant info, pixel color, qo-ords and the like... then you could just create a new image inside gdk and use gdk command like dbPoint to draw your own image... Doing it with media other than images would also be possible, like meshes, you could read the vertex info into a data structure from you data file, and then make a GDK memblock mesh, and copy the data into it etc......
Only reposted this as after thinking about it, accessing GDK using directx manually can be a little long winded and difficult
If it ain't broke.... DONT FIX IT !!!