一个GL门外汉的提问
一个GL外行的提问
有直接支持纵向裁剪的GL函数么 ? 类似于BitBlt的那种 。 要求版本比较低的那种。
LZ的PC机只支持1.0左右的GL。自己写的在裁剪在全屏下比较的慢 。 如果没有顺便想求个方法 。 ( 最近在写一个图形软件。要求实时切换GL/DX/GDI的渲染 )
随便附上自己写的渣代码
------解决思路----------------------
opengl里那个叫scissor
用高版本opengl需要glew。现在不太可能有显卡还只支持1.x的OpenGL。
除非有绝对把握自己能赢得过编译器(对十分熟悉优化的人这倒是可能的...),不要直接写汇编。尤其别在C++里插入汇编玩,64位模式停止支持内联汇编也是有道理的。
有直接支持纵向裁剪的GL函数么 ? 类似于BitBlt的那种 。 要求版本比较低的那种。
LZ的PC机只支持1.0左右的GL。自己写的在裁剪在全屏下比较的慢 。 如果没有顺便想求个方法 。 ( 最近在写一个图形软件。要求实时切换GL/DX/GDI的渲染 )
#include <windows.h>
#include <gl/glut.h>
#define MAIN_WINDOW_WIDTH 256
#define MAIN_WINDOW_HEIGHT 224
static HGLRC gl_rc_handle;
static HWND wnd_handle;
static LPRECT ref_clip_rect;
static _CRT_ALIGN(32) DWORD gl_temp_buffer[(MAIN_WINDOW_WIDTH+8)*(MAIN_WINDOW_HEIGHT+24)];
static _CRT_ALIGN(32) DWORD gl_real_buffer[MAIN_WINDOW_WIDTH*(MAIN_WINDOW_HEIGHT+16)];
VOID __stdcall wglSwapBuffers( HDC );
PDWORD get_gl_buffer( VOID ) {
return gl_temp_buffer;
}
__declspec(naked) gl_do_clip( VOID ) {
__asm {
push esi
push edi
push ebp
push ebx
mov eax, [ref_clip_rect]
mov eax, [eax+12]
cmp eax, 224
je usd
lea esi, [gl_temp_buffer+32]
mov ecx, 240
jmp sdw
usd:
lea esi, [gl_temp_buffer+8480]
mov ecx, 224
sdw:
lea edi, [gl_real_buffer]
mov eax, 1024
mov ebx, 8
mov edx, 1056
mov ebp, 128
align 16
main_loop:
movdqa xmm0, [esi+00h]
movdqa xmm1, [esi+10h]
movdqa xmm2, [esi+20h]
movdqa xmm3, [esi+30h]
movdqa xmm4, [esi+40h]
movdqa xmm5, [esi+50h]
movdqa xmm6, [esi+60h]
movdqa xmm7, [esi+70h]
movdqa [edi+00h], xmm0
movdqa [edi+10h], xmm1
movdqa [edi+20h], xmm2
movdqa [edi+30h], xmm3
movdqa [edi+40h], xmm4
movdqa [edi+50h], xmm5
movdqa [edi+60h], xmm6
movdqa [edi+70h], xmm7
add esi, ebp
add edi, ebp
dec ebx
jne main_loop
mov ebx, 8
dec ecx
lea esi, [ebx*4+esi]
jne main_loop
pop ebx
pop ebp
pop edi
pop esi
ret
}
}
BOOL init_gl( HWND _wnd_handle ) {
HDC dev_context_handle;
PIXELFORMATDESCRIPTOR pfd = { sizeof( PIXELFORMATDESCRIPTOR ),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, PFD_MAIN_PLANE,
0, 0, 0, 0
};
wnd_handle = _wnd_handle;
dev_context_handle = GetDC( wnd_handle );
if ( !dev_context_handle ) {
MessageBoxA( NULL, "GetDC failed", "init opengl", MB_ICONERROR );
return FALSE;
}
if ( !SetPixelFormat( dev_context_handle, ChoosePixelFormat( dev_context_handle, &pfd ), &pfd ) ) {
ReleaseDC( wnd_handle, dev_context_handle);
MessageBoxA( NULL, "SetPixelFormat failed", "init opengl", MB_ICONERROR );
return FALSE;
}
gl_rc_handle = wglCreateContext( dev_context_handle );
if ( !wglMakeCurrent( dev_context_handle, gl_rc_handle ) ) {
ReleaseDC( wnd_handle, dev_context_handle);
MessageBoxA( NULL, "wglMakeCurrent failed", "init opengl", MB_ICONERROR );
return FALSE;
}
ReleaseDC( wnd_handle, dev_context_handle);
return TRUE;
}
VOID gl_post_render( VOID ) {
HDC dev_context_handle;
RECT view_rect;
ref_clip_rect = get_clip_rect();
gl_do_clip();
dev_context_handle = GetDC( wnd_handle );
GetClientRect( wnd_handle, &view_rect );
glRasterPos2i( -1, 1 );
glViewport ( 0, 0, view_rect.right, view_rect.bottom );
glDrawPixels ( 256, ref_clip_rect->bottom == 240 ? 240 : 224,
0x80E1,
GL_UNSIGNED_BYTE,
&gl_real_buffer
);
glPixelZoom ( ( float )view_rect.right / ( float ) 256.0,
- ( ( float )view_rect.bottom / ( float ) ( ref_clip_rect->bottom == 240 ? 240.0 : 224.0 ) )
);
wglSwapBuffers( dev_context_handle );
ReleaseDC( wnd_handle, dev_context_handle);
}
INT uninit_gl( VOID ) {
if ( FALSE == wglMakeCurrent( NULL, NULL ) ) {
return -1;
}
if ( FALSE == wglDeleteContext( gl_rc_handle ) ) {
return -1;
}
return 0;
}
随便附上自己写的渣代码
------解决思路----------------------
opengl里那个叫scissor
用高版本opengl需要glew。现在不太可能有显卡还只支持1.x的OpenGL。
除非有绝对把握自己能赢得过编译器(对十分熟悉优化的人这倒是可能的...),不要直接写汇编。尤其别在C++里插入汇编玩,64位模式停止支持内联汇编也是有道理的。