Source / code snippets | | | | | first Anfängerversuche with "glReadPixels" of me.
of these commands CompileMarkSeparation"ogl("glReadPixels",x,y,xw,yh+,~GL_RGBA,~GL_UNSIGNED_BYTE,bereich#) " > can in the Context with CompileMarkSeparation the Openglfenster as Graphic image in a Memory-Variable reinpacken and evaluate for evtl Collisionen, first by me in 2D, or Show, How in the demonstration. The selection is the Fontbuffer or the Backbuffer.
x and y is the point in the OpenGL-Window of where from The wide xw and the Höhe yh into Memory-Variable read becomes. One point corresponds to 4 byte (RGBA), properly must The Memory-Variable laid out go. Since I one Image of 128x128 Pixel have , is the Memory-Variable by me 128*128*4.
I have by me one OpenGlFenster of 350x350 Pixel. my Image read I with x=140 and y=140 from , with of/ one wide of 128 and of/ one Höhe of 128 , circa it simply To hold circa for my attempt no new CompileMarkSeparation"bild_h& = Create("hPic", -1, namebild$)" > anzulegen. chosen have I the Backbuffer.
of these commands : ~setDIBits(%hdc,bild_h&,0,bmi#.biHeight&,area#,bmi#,0) read I the image into lever bild_h& one, one can also here again other lever with "bild_h& = Create("HPIC", -1, namebild$)" lay out. the knows I not yet, how to make a lever festlegt with Create without a BMP(Image) reinzusetzen. and make this Image of "glReadPixels" on the Mainwindow left(not OpenGlFenster) visible with "drawpic bild_h&,10,10,0".
before must again 2 BMP-Images laid out go, once whom background and once one Objekt to that steer. XPIA must again activate go.
Please these demonstration with new ideas bestücken, Perhaps have your yet integral better Einfälle circa this auszubauen. These demonstration is only one I-Tüpflelchen, is time a idea, The at the beginning standing.
The colours are yet vertauscht of Image "glReadPixels", because these andersherum be read. CompileMarkSeparation $H Windows.ph
If 0
AsmStart rgb_umwandlung
Parameters bildxy#,a&
LOCAL r :BYTE
LOCAL g :BYTE
LOCAL b :BYTE
LOCAL w :DWORD
mov eax,para2
mov w,eax
mov ecx,0
mov ebx,para1
.while ecx<=w
mov al,[ebx+ecx]
mov b,al
mov al,[ebx+ecx+1]
mov g,al
mov al,[ebx+ecx+2]
mov r,al
and b,255
and g,255
and r,255
mov al,b
.if al>0
jmp wandle
.endif
mov al,g
.if al>0
jmp wandle
.endif
mov al,r
.if al>0
jmp wandle
.endif
mov al,0
mov [ebx+ecx+3],al
mov al,b
mov [ebx+ecx+2],al
mov al,r
mov [ebx+ecx],al
jmp weiter
wandle:
mov al,255
mov [ebx+ecx+3],al
mov al,b
mov [ebx+ecx+2],al
mov al,r
mov [ebx+ecx],al
weiter:
add ecx,4
.endw
AsmEnd
EndIf
declare bild1$
declare x1!,y1!,dx!,dy!,winkel!
declare hWin&
declare width%,height%
declare bild_h&,a&
declare bmi#,bildxy# ,ogl_rgb#
var groesse%=128*128*4
dim ogl_rgb#,groesse%
var texid%=0
Window 20,20-600,450
Cls @RGB(220,220,220)
hWin& = @Create("text", %hWnd, "Test1", 220, 10, 350, 350)
oGL("Init", hwin&, 0,0, 0, 0)
oGL("PosMode", 1)
bild1$="auto.bmp"
var tex.auto%=erzeugetex(bild1$)
var tex.grund%=OGL("loadtexturebmp","tile1.bmp",3)
var ende%=1
WHILE ende%
sleep 1
if isKey(65)
ende% = 0
endif
if isKey(81)
winkel!=winkel!+0.4
endif
if isKey(69)
winkel!=winkel!-0.4
endif
if isKey(87)
y1!=Sin(winkel!/180.0*pi())*0.02
x1!=Cos(winkel!/180.0*pi())*0.02
dx!=dx!-x1!
dy!=dy!-y1!
endif
if isKey(83)
y1!=Sin(winkel!/180.0*pi())*0.02
x1!=Cos(winkel!/180.0*pi())*0.02
dx!=dx!+x1!
dy!=dy!+y1!
endif
ogl("glReadBuffer",~GL_Back)
ogl("glReadPixels",140,140,128,128,~GL_RGBA,~GL_UNSIGNED_BYTE,ogl_rgb#)
~setDIBits(%hdc,bild_h&,0,bmi#.biHeight&,ogl_rgb#,bmi#,0)
drawpic bild_h&,10,10,0
drawglscene()
ENDWHILE
proc drawglscene
OGL("Clear")
OGL("move",0,0,-3)
OGL("texture",tex.grund%,10)
OGL("move",0,0,0)
OGL("quad",8,8)
OGL("origin",dx!,dy!,-3)
OGL("texture",tex.auto%,1)
OGL("rotate",0,0,winkel!)
OGL("quad",0.7,0.7)
OGL("show")
endproc
proc erzeugetex
parameters namebild$
mcls 0,0,0
startpaint -1
mloadbmp namebild$,0,0
endpaint
height%=%bmpx
width%=%bmpy
def &BI_RGB 0
def &DIB_RGB_COLORS 0
struct BITMAPINFOHEADER =
biSize&, biWidth&, biHeight&, biPlanes%, biBitCount%, biCompression&,
biSizeImage&, biXPelsPerMeter&, biYPelsPerMeter&, biClrUsed&, biClrImportant&
dim bmi#,BITMAPINFOHEADER
clear bmi#
with bmi#
.biSize& = sizeof(bmi#)
.biWidth& = width%
.biHeight& = height%
.biPlanes% = 1
.biBitCount% = 32
.biCompression& = &BI_RGB
.biSizeImage& = ((.biWidth& * .biBitCount% 8 - 1) | 3 + 1) * abs(.biHeight&)
endwith
bild_h& = Create("hPic", -1, namebild$)
a&=bmi#.biSizeImage&
dim bildxy#,a&
~GetDIBits(%hdc,bild_h&,0,bmi#.biHeight&,bildxy#,bmi#,0)
Call(xpia_getprocaddressm(xpia_hmodule&,"rgb_umwandlung"),bildxy#,a&)
OGL("glGenTextures",1,ADDR(texid%))
OGL("glBindTexture",~GL_TEXTURE_2D,texid%)
OGL("glEnable",~GL_ALPHA_TEST)
OGL("glAlphaFunc",~GL_GREATER, 0.1)
OGL("glTexParameteri",~GL_TEXTURE_2D, ~GL_TEXTURE_MAG_FILTER, ~GL_LINEAR)
OGL("glTexParameteri",~GL_TEXTURE_2D, ~GL_TEXTURE_MIN_FILTER, ~GL_LINEAR)
OGL("gluBuild2DMipmaps",~GL_TEXTURE_2D, ~GL_RGBA, height%, width%, ~GL_RGBA, ~GL_UNSIGNED_BYTE, bildxy#)
dispose bmi#
dispose bildxy#
RETURN texid%
endproc
|
| | | | |
| | | have a Solution for the vain lever found :
declare bild_h1&
mcls 128,128,0 bild_h1& = Create("HPIC", 0,"&MEMBMP" )
now must these both command so equips go :
~setDIBits(%hdc,bild_h1&,0,128,ogl_rgb#,bmi#,0)
drawpic bild_h1&,10,10,0
furthermore whom right Parameter found, so The colours not vertauscht go :
~GL_BGRA instead of ~GL_RGBA , means:
ogl("glReadPixels",140,140,128,128,~GL_BGRA,~GL_UNSIGNED_BYTE,ogl_rgb#)
mfg |
| | | | |
| | | The Thread is "hier" under programs but wrong stored, one Admin Please move. |
| | | | |
|
Zum QuelltextThemeninformationenthis Topic has 2 subscriber: |