10 个解决方案
#1
自己试试就知道了。当然是可以在内存里面着色的···
#2
就是怎麼試都不成功才問的啊, 我覺得比較關鍵的地方是 SetPixelFormat 中設定的參數可能有影響. 大家幫忙啊, 120 分呢.
#3
就是怎麼試都不成功才問的啊, 我覺得比較關鍵的地方是 SetPixelFormat 中設定的參數可能有影響. 大家幫忙啊, 120 分呢.
#4
不惜血本,再加10分, 也只能加這麼多了.
#5
有兴趣,非常有兴趣,要是有例子就更好了
#6
帖点代码来看看····
#7
在PixelFormat的Flag中加入PFD_DRAW_TO_BITMAP标志
#8
这个bitmap是在系统内存还是在显存里?
#9
問題的答案應該是可以的,關鍵部分是幾個函數的調用順序和所傳參數的值要正確.
下面貼出簡單的Code,沒有做什麼錯誤處理.為了方便起見,是在C++ Builder中寫的,在一個
Form上丟了一個Panel和一個Button, 在Button OnClick寫了下面的部分.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HDC hDC, hMemDC;
HBITMAP hBmp, hOldBmp;
HGLRC hRC;
GLfloat w, h;
w = Panel1->ClientWidth;
h = Panel1->ClientHeight;
hDC = GetDC(Panel1->Handle);
hMemDC = CreateCompatibleDC(hDC);
hBmp = CreateCompatibleBitmap(hDC, (int)w, (int)h);
hOldBmp = (HBITMAP)SelectObject(hMemDC, hBmp);
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
int PixelFormat = ChoosePixelFormat(hMemDC, &pfd);
SetPixelFormat(hMemDC, PixelFormat, &pfd);
hRC = wglCreateContext(hMemDC);
wglMakeCurrent(hMemDC, hRC);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
glOrtho (0, 50, 0, 50, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex3f(10.0, 10.0, 0.0);
glVertex3f(40.0, 40.0, 0.0);
glEnd();
glFlush();
BitBlt(hDC, 0, 0, (int)w, (int)h, hMemDC, 0, 0, SRCCOPY);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
SelectObject(hMemDC, hOldBmp);
DeleteObject(hBmp);
DeleteDC(hMemDC);
ReleaseDC(Panel1->Handle, hDC);
}
再次感謝大家的關注和幫助.
下面貼出簡單的Code,沒有做什麼錯誤處理.為了方便起見,是在C++ Builder中寫的,在一個
Form上丟了一個Panel和一個Button, 在Button OnClick寫了下面的部分.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HDC hDC, hMemDC;
HBITMAP hBmp, hOldBmp;
HGLRC hRC;
GLfloat w, h;
w = Panel1->ClientWidth;
h = Panel1->ClientHeight;
hDC = GetDC(Panel1->Handle);
hMemDC = CreateCompatibleDC(hDC);
hBmp = CreateCompatibleBitmap(hDC, (int)w, (int)h);
hOldBmp = (HBITMAP)SelectObject(hMemDC, hBmp);
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
int PixelFormat = ChoosePixelFormat(hMemDC, &pfd);
SetPixelFormat(hMemDC, PixelFormat, &pfd);
hRC = wglCreateContext(hMemDC);
wglMakeCurrent(hMemDC, hRC);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
glOrtho (0, 50, 0, 50, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex3f(10.0, 10.0, 0.0);
glVertex3f(40.0, 40.0, 0.0);
glEnd();
glFlush();
BitBlt(hDC, 0, 0, (int)w, (int)h, hMemDC, 0, 0, SRCCOPY);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
SelectObject(hMemDC, hOldBmp);
DeleteObject(hBmp);
DeleteDC(hMemDC);
ReleaseDC(Panel1->Handle, hDC);
}
再次感謝大家的關注和幫助.
#10
另外, DRAW_TO_BITMAP 是不能在這裡用的, 但是應該在什麼情況下用這個Flag呢, 希望大家指教.
#1
自己试试就知道了。当然是可以在内存里面着色的···
#2
就是怎麼試都不成功才問的啊, 我覺得比較關鍵的地方是 SetPixelFormat 中設定的參數可能有影響. 大家幫忙啊, 120 分呢.
#3
就是怎麼試都不成功才問的啊, 我覺得比較關鍵的地方是 SetPixelFormat 中設定的參數可能有影響. 大家幫忙啊, 120 分呢.
#4
不惜血本,再加10分, 也只能加這麼多了.
#5
有兴趣,非常有兴趣,要是有例子就更好了
#6
帖点代码来看看····
#7
在PixelFormat的Flag中加入PFD_DRAW_TO_BITMAP标志
#8
这个bitmap是在系统内存还是在显存里?
#9
問題的答案應該是可以的,關鍵部分是幾個函數的調用順序和所傳參數的值要正確.
下面貼出簡單的Code,沒有做什麼錯誤處理.為了方便起見,是在C++ Builder中寫的,在一個
Form上丟了一個Panel和一個Button, 在Button OnClick寫了下面的部分.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HDC hDC, hMemDC;
HBITMAP hBmp, hOldBmp;
HGLRC hRC;
GLfloat w, h;
w = Panel1->ClientWidth;
h = Panel1->ClientHeight;
hDC = GetDC(Panel1->Handle);
hMemDC = CreateCompatibleDC(hDC);
hBmp = CreateCompatibleBitmap(hDC, (int)w, (int)h);
hOldBmp = (HBITMAP)SelectObject(hMemDC, hBmp);
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
int PixelFormat = ChoosePixelFormat(hMemDC, &pfd);
SetPixelFormat(hMemDC, PixelFormat, &pfd);
hRC = wglCreateContext(hMemDC);
wglMakeCurrent(hMemDC, hRC);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
glOrtho (0, 50, 0, 50, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex3f(10.0, 10.0, 0.0);
glVertex3f(40.0, 40.0, 0.0);
glEnd();
glFlush();
BitBlt(hDC, 0, 0, (int)w, (int)h, hMemDC, 0, 0, SRCCOPY);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
SelectObject(hMemDC, hOldBmp);
DeleteObject(hBmp);
DeleteDC(hMemDC);
ReleaseDC(Panel1->Handle, hDC);
}
再次感謝大家的關注和幫助.
下面貼出簡單的Code,沒有做什麼錯誤處理.為了方便起見,是在C++ Builder中寫的,在一個
Form上丟了一個Panel和一個Button, 在Button OnClick寫了下面的部分.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HDC hDC, hMemDC;
HBITMAP hBmp, hOldBmp;
HGLRC hRC;
GLfloat w, h;
w = Panel1->ClientWidth;
h = Panel1->ClientHeight;
hDC = GetDC(Panel1->Handle);
hMemDC = CreateCompatibleDC(hDC);
hBmp = CreateCompatibleBitmap(hDC, (int)w, (int)h);
hOldBmp = (HBITMAP)SelectObject(hMemDC, hBmp);
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
int PixelFormat = ChoosePixelFormat(hMemDC, &pfd);
SetPixelFormat(hMemDC, PixelFormat, &pfd);
hRC = wglCreateContext(hMemDC);
wglMakeCurrent(hMemDC, hRC);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
glOrtho (0, 50, 0, 50, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex3f(10.0, 10.0, 0.0);
glVertex3f(40.0, 40.0, 0.0);
glEnd();
glFlush();
BitBlt(hDC, 0, 0, (int)w, (int)h, hMemDC, 0, 0, SRCCOPY);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
SelectObject(hMemDC, hOldBmp);
DeleteObject(hBmp);
DeleteDC(hMemDC);
ReleaseDC(Panel1->Handle, hDC);
}
再次感謝大家的關注和幫助.
#10
另外, DRAW_TO_BITMAP 是不能在這裡用的, 但是應該在什麼情況下用這個Flag呢, 希望大家指教.