|
Hi, i am writing a small app for a WMP Visualization. The app can be downloaded here[^] and the viz can be found here[^].
Can someone please have a look at the code and tell me what's wrong. For starters, i want to render an image in the background then warp it and draw it back to the screen. There are some problems with that. I use RAD C++ for the GUI (http://www.radcpp.com).
Here is some of the code
void Graphics::copyToTexture(WarpFile &wf) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
renderBackground(wf);
glCallList(displayList[DL_TEX_ENABLE]);
glBindTexture(GL_TEXTURE_2D, image);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); glVertex2f(0, 0);
glTexCoord2f(0, 0); glVertex2f(0, 512);
glTexCoord2f(1, 0); glVertex2f(512, 512);
glTexCoord2f(1, 1); glVertex2f(512, 0);
glEnd();
glBindTexture(GL_TEXTURE_2D, backTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0);
glCallList(displayList[DL_TEX_DISABLE]);
glBindTexture(GL_TEXTURE_2D,0);
SwapBuffers(hdc);
}
It needs to be compiled with Dev-C++, you may need OpenGLUT.dll i forgot to include it in the zip file.
Can someone please help me
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
I would like to help, but you don't say what the problem is. And I don't want to spend an afternoon going through code. Maybe you could say what you expected to obtain and what it is that you are obtaining? Also, I know OpenGL but I don't know what is a WMP.
It seems to me you are trying to draw something and then make OpenGL modify it for you. I'm not sure I understand what you want but in general you already have to have your data ready when you call OpenGL to render a 3D world. OpenGL is the one doing all the drawing (generally speaking) and usually doesn't process (or modify) an already drawn image.
I once made an application to wrap the real-time video feed from a web cam onto a 3D virtual object in the OpenGL world. Do you want to do something like that?
Rilhas
|
|
|
|
|
Rilhas wrote: I once made an application to wrap the real-time video feed from a web cam onto a 3D virtual object in the OpenGL world. Do you want to do something like that?
Pretty much. WMP stands for Windows Media Player and i am making a visualization for it. That is the image that is shown when you play a song. It is a moving image that is rendered in real-time and usually moves to the beat of the song. I want to warp the image i have drawn using a 2D array of warp points. I am currenty making an app that edits those points. When it draws the image, it renders it to a texture then draws quads using the points and maps the a section of the texture to it's respective quad. I then copy the screen (with the warped image) back to that texture and do the whole thing again each frame. The result is that the image has a blur/trace effect where the warped image constantly fades into the background.
Here are some pics http://img519.imageshack.us/img519/1388/viz1kx4.th.png http://img99.imageshack.us/img99/4991/screenshot4kj7.th.jpg
Check out the SwapBuffers post to see my latest problem and see if you can help me their.
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
HDC hdcWindow;
static int nScreenWidth, nScreenHeight;
switch (message)
{
case WM_CREATE:
nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
SetTimer( hwnd,0,2000,NULL);
return 0 ;
case WM_LBUTTONDOWN:
{
HWND tBarHandle= NULL;
return 0;
}
case WM_PAINT:
{
hdc = BeginPaint (hwnd, &ps) ;
hdcWindow = GetWindowDC( hwnd);
HWND hDesktopWnd = GetDesktopWindow();
HDC Source = GetDC(hDesktopWnd);
HDC Destination = CreateCompatibleDC(Source);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight);
SelectObject(Destination,hCaptureBitmap);
BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY);
BitBlt(hdc,0,0 , nScreenWidth, nScreenHeight, Source, 0,0, SRCCOPY);
ReleaseDC(hDesktopWnd,Destination);
DeleteDC(Source);
DeleteObject(hCaptureBitmap);
EndPaint (hwnd, &ps) ;
}
return 0 ;
case WM_TIMER:
GetClientRect(hwnd,&rect);
InvalidateRect( hwnd, &rect, true);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
How to convert DDB format to DIB format using GETDIBits() function ????
|
|
|
|
|
Something like this maybe...
(warning - I haven't provided for a color table of any kind!! This means this won't work for a
palette-based video mode or a non BI_RGB DIB, which is why I force it to BI_RGB)
int nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
HDC Source = ::GetDC(0);
HDC Destination = ::CreateCompatibleDC(Source);
HBITMAP hCaptureBitmap = ::CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight);
HGDIOBJ hOldBm = ::SelectObject(Destination, hCaptureBitmap);
::BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY);
::SelectObject(Destination, hOldBm);
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, NULL, &bmi, DIB_RGB_COLORS);
bmi.bmiHeader.biCompression = BI_RGB;
BYTE *pPixelBytes = new BYTE[bmi.bmiHeader.biSizeImage];
::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, pPixelBytes, &bmi, DIB_RGB_COLORS);
::ReleaseDC(0, Source);
::DeleteDC(Destination);
::DeleteObject(hCaptureBitmap);
delete[] pPixelBytes;
Also make sure you use the correct ReleaseDC/DeleteDC calls on the appropriate DCs.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I have no idea whatsoever about how to start learning how to do graphic designing but i want to get into a career in that field any help or ideas would be nice
|
|
|
|
|
This is a programming forum. By definition, most of us know nothing about graphic design, either. Is that really what you mean ? Or do you mean graphics programming ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: By definition, most of us know nothing about graphic design
well, that's not entirely true.... but I don't know how to direct someone to find the information outside of google. You want, you find, you learn -- that is the only method I ever used. There is a graphics design degree offered at our college, but I doubt he would want to come here.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Can you be more specific.
|
|
|
|
|
Hi,
I want to create a user control which permits to visualize OpenGl inside of it.
How can i do it?
Thx,
Nuno
|
|
|
|
|
|
hi..my program is in C++ with openGL..I have open 1 window to display my objects..but i need to open another window to display the result of processing executed on same object..
my code like this
#include ....
....
routine for processing object(like filter)
....
...
//after that processing i need to open a new window to display results(another image) with keeping the original window open to see diferences.
int main
creat window....
//here the original window of the object before processing it.regards
|
|
|
|
|
Miss_ Petrovna wrote: hi..my program is in C++ with openGL..I have open 1 window to display my objects..but i need to open another window to display the result of processing executed on same object..
http://users.encs.concordia.ca/~grogono/Graphics/examples.html[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Thanks alot ... its very good website .. Petrovna
|
|
|
|
|
When performance is not an issue and when all that we want is just a snapshot of the desktop, we can consider the GDI option. This mechanism is based on the simple principle that the desktop is also a window - that is it has a window Handle (HWND) and a device context (DC). If we can get the device context of the desktop to be captured, we can just blit those contents to our application defined device context in the normal way. And getting the device context of the desktop is pretty straightforward if we know its window handle - which can be achieved through the function GetDesktopWindow(). Thus, the steps involved are:
Acquire the Desktop window handle using the function GetDesktopWindow();
Get the DC of the desktop window using the function GetDC();
Create a compatible DC for the Desktop DC and a compatible bitmap to select into that compatible DC. These can be done using CreateCompatibleDC() and CreateCompatibleBitmap(); selecting the bitmap into our DC can be done with SelectObject();
Whenever you are ready to capture the screen, just blit the contents of the Desktop DC into the created compatible DC - that's all - you are done. The compatible bitmap we created now contains the contents of the screen at the moment of the capture.
Do not forget to release the objects when you are done. Memory is precious (for the other applications).
Void CaptureScreen()
{
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hCaptureBitmap);
BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,
hDesktopDC,0,0,SRCCOPY|CAPTUREBLT);
SaveCapturedBitmap(hCaptureBitmap); //Place holder - Put your code
//here to save the captured image to disk
ReleaseDC(hDesktopWnd,hDesktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
}
In the above code snippet, the function GetSystemMetrics() returns the screen width when used with SM_CXSCREEN, and returns the screen height when called with SM_CYSCREEN. Refer to the accompanying source code for details of how to save the captured bitmap to the disk and how to send it to the clipboard. Its pretty straightforward. The source code implements the above technique for capturing the screen contents at regular intervals, and creates a movie out of the captured image sequences.
In consideration to the above code please let me know how to capture the network PC`s desktop to my software..
I want to capture it continously i dont want to save it, i want it`s Rectangular Area in ma software...
Please let me know how to do this(of course sockets are used) or create a method for this...
|
|
|
|
|
A process running on the remote system would call CaptureScreen() at regular intervals (however
many frames-per-second you want). Instead of SaveCapturedBitmap(), you would probably want to
SendCapturedBitmap(...). A SendCapturedBitmap() implementaion would transfer the serialized
bitmap bits over a socket to a remotely connected process.
That's the basics but there's some issues...
Getting the bitmap bits. I prefer using DIBSections but GetDIBits() is fine too.
Bandwidth. Multiply the number of bytes per frame by the frames per second. Is it possible to
send that many bytes-per-second over the network without compression?
Which part is giving you trouble? What have you tried so far?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Actually i cant get the main idea how to send on sockets..
void SaveBitmap(char *szFilename,HBITMAP hBitmap)
{
HDC hdc=NULL;
FILE* fp=NULL;
LPVOID pBuf=NULL;
BITMAPINFO bmpInfo;
BITMAPFILEHEADER bmpFileHeader;
do{
hdc=GetDC(NULL);
ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
if(bmpInfo.bmiHeader.biSizeImage<=0)
bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
if((pBuf=malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
{
MessageBox(NULL,_T("Unable to Allocate Bitmap Memory"),_T("Error"),MB_OK|MB_ICONERROR);
break;
}
bmpInfo.bmiHeader.biCompression=BI_RGB;
GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS);
if((fp=fopen(szFilename,"wb"))==NULL)
{
MessageBox(NULL,_T("Unable to Create Bitmap File"),_T("Error"),MB_OK|MB_ICONERROR);
break;
}
bmpFileHeader.bfReserved1=0;
bmpFileHeader.bfReserved2=0;
bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
bmpFileHeader.bfType='MB';
bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
}while(false);
if(hdc)
ReleaseDC(NULL,hdc);
if(pBuf)
free(pBuf);
if(fp)
fclose(fp);
}
This is the implementation of savebitmap..... and how to sendbitmap i dont know... Please help me.. I want to submit it by 3rd may... else ma 30 numbers would be ruined.
|
|
|
|
|
In theory, you should be able to replace the fwrite() calls with socket send() calls.
In practice, you can improve your protocol by sending the headers only once. This information
only changes if you change the capture rect size or the screen resolution and/or bitdepth changes
so for each captured frame you only need to send the pixel data.
Also, I'm not sure about this calculation:
bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
The pixel data is aligned to a DWORD (4-byte) boundary for each row so maybe something like this:
long lStride = ((bmpInfo.bmiHeader.biWidth * (long)bmpInfo.bmiHeader.biBitCount + 31L) & ~31L) / 8L;
bmpInfo.bmiHeader.biSizeImage = lStride * abs(bmpInfo.bmiHeader.biHeight);
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
HassanKU wrote: In consideration to the above code please let me know how to capture the network PC`s desktop to my software..
Do you have a process running on the remote machine that is capturing its screen and sending it back to the calling machine?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Actually can i send u my application.... ???
Please give me ur email address...
|
|
|
|
|
Yes server is requesting da desktop of network Pc...
and the capturing method is running on network PC.
|
|
|
|
|
HassanKU wrote: ...and the capturing method is running on network PC.
Is this part working?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
You need to scale this large problem down into several smaller problems. I would be inclined to first get the actual communication working at a very basic level before anything else. The calling machine(s) should be able to send multiple requests to the remote machine without any of them being lost. The remote machine could simply write "Received request from xxx." to a file of some sort.
Then I would have the remote machine "answer" those requests by being able to take a snapshot of its desktop. Simply send a 0 or 1 back to the calling machine to indicate success or failure. Have the calling machine display this acknowledgment.
More to come...
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|