 |
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
funkeld gesperrt
Anmeldungsdatum: 10.10.2009 Beiträge: 179
|
Verfasst am: 02.03.2010, 12:41 Titel: Openglscreen in FBscreen kopieren |
|
|
Wenn man mit der LM das linke fenster anklickt , kann man den Ball mit der Maus bewegen.
Links ist der FBScreen und rechts der Openglscreen.
Der FBScreen wird in den Opengl-Screen kopiert.
Ich finde gedanklich und praktisch keine Lösung, wie man mal den Openglscreen in ein FBScreen reingekommt als Bild
Wer kann man helfen, das es in diesem Programm funktioniert?
Code: |
#Include once "/gl/gl.bi"
#include once "/gl/glu.bi"
#include once "/gl/glfw.bi"
#include once "/fbgfx.bi"
Using FB
Const As Integer SCR_WIDTH = 640
Const As Integer SCR_HEIGHT = 480
Const As Integer BITSPP = 32
Const As Integer BUFF_WIDTH = 320
Const As Integer BUFF_HEIGHT = 240
Const As Integer TEX_WIDTH = 512
Const As Integer TEX_HEIGHT = 512
Dim Shared As Integer zz,new_x, new_y
Type Tdisplay
w As Uinteger
h As Uinteger
r_bits As Uinteger
g_bits As Uinteger
b_bits As Uinteger
a_bits As Uinteger
d_bits As Uinteger
s_bits As Uinteger
mode As Uinteger
Glver As Zstring Ptr
As Single FOVy, aspect, znear, zfar
End Type
Type Tfbgfx_2_GL
Declare Constructor()
Declare Destructor()
Public:
Declare Property image() As Any Ptr
Declare Sub init_gl_screen()
Declare Sub view_ortho()
Declare Sub view_perspective()
Declare Sub render()
Private:
s_display As Tdisplay
texture_id As GLuint
p_image As Any Ptr
p_image_texture As Any Ptr
p_texture_data As GLuint Ptr
End Type
Declare Sub init_cube()
Declare Sub draw_cube()
Constructor Tfbgfx_2_GL()
ScreenRes BUFF_WIDTH,BUFF_HEIGHT,32
sCREENCONTROL SET_WINDOW_POS, 10,200
p_image = Imagecreate(BUFF_WIDTH,BUFF_HEIGHT,0)
p_image_texture = Imagecreate(TEX_WIDTH,TEX_HEIGHT,0)
If glfwInit() Then
'Successful!
Else
Print "Failed to initialize GLFW!"
Sleep 1000
End
End If
s_display.w = SCR_WIDTH
s_display.h = SCR_HEIGHT
s_display.r_bits = 8
s_display.g_bits = 8
s_display.b_bits = 8
s_display.a_bits = 8
s_display.d_bits = 8
s_display.s_bits = 8
s_display.mode = GLFW_WINDOW
'Open a GLFW window
If glfwOpenWindow( _
s_display.w , _
s_display.h , _
s_display.r_bits, _
s_display.g_bits, _
s_display.b_bits, _
s_display.a_bits, _
s_display.d_bits, _
s_display.s_bits, _
s_display.mode ) _
Then
glfwSwapInterval 1
s_display.GlVer = glGetString(GL_VERSION)
Else
glfwTerminate()
End
End If
Dim xvid As GLFWvidmode
glfwGetDesktopMode( @xvid )
glfwSetWindowPos( (xvid.width-s_display.w)\2, (xvid.height-s_display.h)\2 )
glfwSetWindowTitle("FBGFX_2_GL by relsoft 2010")
'Initialize OpenGL patamaters
init_gl_screen()
'init texture
Dim As Uinteger Ptr pixdata
Dim As Integer res,wid,hei,bpp,pitch,imgsize
'get GET/PUT data from header
res = imageinfo(p_image_texture, wid, hei, bpp, pitch, pixdata, imgsize)
'Poinnt our texture buffer to the pixeldata
p_texture_data = pixdata
'Enables OGL texturing
glEnable (GL_TEXTURE_2D)
'Generate 1 texture for our FB image buffer,
'Bind it and set up parameters
glGenTextures(1, @texture_id)
glBindTexture(GL_TEXTURE_2D, texture_id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0,_
GL_RGBA, GL_UNSIGNED_BYTE, p_texture_data)
'This is the parameter to use normally
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
'This one would give you a bi-filter for free
'Try to uncomment the 2 lines below.
'glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
'glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
End Constructor
Destructor Tfbgfx_2_GL()
'free our texture
glDeleteTextures(1, @texture_id)
'close GLFW
glfwTerminate()
' destroy our image buffers
imagedestroy (p_image)
imagedestroy (p_image_texture)
End Destructor
Property Tfbgfx_2_GL.image() As Any Ptr
Property = p_image
End Property
Sub Tfbgfx_2_GL.init_gl_screen()
'screen information
Dim w As Integer, h As Integer
'OpenGL params for gluerspective
Dim FOVy As Double 'Field of view angle in Y
Dim Aspect As Double 'Aspect of screen
Dim znear As Double 'z-near clip distance
Dim zfar As Double 'z-far clip distance
'using screen info w and h as params
glViewport(0, 0, s_display.w, s_display.h)
'Set current Mode to projection(ie: 3d)
glMatrixMode(GL_PROJECTION)
'Load identity matrix to projection matrix
glLoadIdentity()
'Set gluPerspective params
FOVy = 80/2 '45 deg fovy
Aspect = s_display.w/ s_display.h
znear = 1 'Near clip
zfar = 500 'far clip
'use glu Perspective to set our 3d frustum dimension up
gluPerspective(FOVy, aspect, znear, zfar)
'Modelview mode
'ie. Matrix that does things to anything we draw
'as in lines, points, tris, etc.
glMatrixMode(GL_MODELVIEW)
'load identity(clean) matrix to modelview
glLoadIdentity()
glShadeModel(GL_SMOOTH) 'set shading to smooth(try GL_FLAT)
glClearColor(0.0, 0.0, 0.0, 1.0) 'set Clear color to BLACK
glClearDepth(1.0) 'Set Depth buffer to 1(z-Buffer)
glEnable(GL_DEPTH_TEST) 'Enable Depth Testing so that our z-buffer works
'compare each incoming pixel z value with the z value present in the depth buffer
'LEQUAL means than pixel is drawn if the incoming z value is less than
'or equal to the stored z value
glDepthFunc(GL_LEQUAL)
'have one or more material parameters track the current color
'Material is your 3d model
glEnable(GL_COLOR_MATERIAL)
'Enable Texturing
glEnable(GL_TEXTURE_2D)
'Set blending parameters
glBlendFunc(GL_SRC_ALPHA, GL_ONE)
'Tell openGL that we want the best possible perspective transform
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
'Tell OpenGL that we need to fill polygons
glPolygonMode(GL_FRONT, GL_FILL)
End Sub
Sub Tfbgfx_2_GL.view_ortho()
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(0, s_display.w, 0,s_display.h, -1, 1)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
End Sub
Sub Tfbgfx_2_GL.view_perspective()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
End Sub
Sub Tfbgfx_2_GL.render()
screenlock ()
'Put the 320 x 240 buffer to the 512 x 512 buffer
Put p_image_texture,(0,0),p_image,Pset
Put (0,0),p_image,Pset
ScreenUnLock ()
'Upload the 512 x 512 buffer to the GPU
'You can also use glTexImage2D()
glTexSubImage2D (GL_TEXTURE_2D,0, 0, 0, TEX_WIDTH, TEX_HEIGHT,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8, p_texture_data)
'OpenGL drawing time
GlMatrixMode (GL_MODELVIEW)
glloadidentity ()
glClear (GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT)
'These are texture coords for
'The quad we draw on the screen.
Dim As Single sx
Dim As Single sy
Dim As Single sw
Dim As Single sh
'Much like the screen coords
'But we need to normalize sw,sh as
'Our actual useable area is greater than what needs
'To be drawn on screen.
sx = 0
sy = 0
sw = BUFF_WIDTH/TEX_WIDTH
sh = BUFF_HEIGHT/TEX_HEIGHT
'Set up color to pure white at full alpha
glColor4f(1.0f,1.0f,1.0f,1.0f)
glPolygonMode(GL_FRONT, GL_FILL)
glPolygonMode(GL_BACK, GL_FILL)
glDisable (GL_BLEND)
glDisable (GL_DEPTH_TEST)
glEnable (GL_TEXTURE_2D)
'draw the qu
glPushMatrix()
view_ortho() ' go to 2d mode
glBegin(GL_QUADS)
glTexCoord2f(sx, sy): glVertex2i(0, s_display.h - 1)
glTexCoord2f(sw, sy): glVertex2i(s_display.w - 1, s_display.h - 1)
glTexCoord2f(sw, sh): glVertex2i(s_display.w - 1, 0)
glTexCoord2f(sx, sh): glVertex2i(0,0)
glEnd()
view_perspective() ' back 3d mode
glPopMatrix()
End Sub
Dim As Tfbgfx_2_GL video
Dim As GLuint cube
Dim As Single time_start = 0
Dim As Double t=Timer,fc=0
Dim As Integer x, dx=5, y, dy=4
Do
'Draw FBGFX stuff here
screenlock ()
Line video.image,(0,0)-(BUFF_WIDTH-1,BUFF_HEIGHT-1),rgb(0,0,0),bf
zz=zz+1
Draw String video.image,(10,140),"hallo pebisoft " & zz,rgb(255,0,0)
Line video.image,(0,0)-(BUFF_WIDTH-1,BUFF_HEIGHT-1),rgb(255,0,0)
getmouse new_x, new_y
Circle video.image, (new_x, new_y), 10, &HFFFFFFFF,,, 1, F
ScreenUnLock()
'set up OGL and clear the frame buffer
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT)
'Render FBGFX_2_GL
video.render
'Draw some openGL eyecandy
draw_cube()
'limit frames
'Too lazy to do a timebased demo
Do
Sleep(1,1)
Loop Until glfwgettime() - time_start >= (1/60)
time_start = glfwgettime()
'flip
GlfwSwapBuffers ()
Loop Until glfwGetKey( GLFW_KEY_ESC )
gldeleteLists(cube,1)
End
Sub init_cube()
Dim As Single col = 1.0
glBegin(GL_QUADS)
'Front Face
glColor3f(0.0, 0.0,col): glVertex3f(-1.0, -1.0, 1.0)
glColor3f(col, 0.0,col): glVertex3f( 1.0, -1.0, 1.0)
glColor3f(col, col,col): glVertex3f( 1.0, 1.0, 1.0)
glColor3f(0.0, col,col): glVertex3f(-1.0, 1.0, 1.0)
'Back Face
glColor3f(col, 0.0,col): glVertex3f(-1.0, -1.0, -1.0)
glColor3f(col, col,col): glVertex3f(-1.0, 1.0, -1.0)
glColor3f(0.0, col,col): glVertex3f( 1.0, 1.0, -1.0)
glColor3f(0.0, 0.0,col): glVertex3f( 1.0, -1.0, -1.0)
'Top Face
glColor3f(0.0, col,col): glVertex3f(-1.0, 1.0, -1.0)
glColor3f(0.0, 0.0,col): glVertex3f(-1.0, 1.0, 1.0)
glColor3f(col, 0.0,col): glVertex3f( 1.0, 1.0, 1.0)
glColor3f(col, col,col): glVertex3f( 1.0, 1.0, -1.0)
'Bottom Face
glColor3f(col, col,col): glVertex3f(-1.0, -1.0, -1.0)
glColor3f(0.0, col,col): glVertex3f( 1.0, -1.0, -1.0)
glColor3f(0.0, 0.0,col): glVertex3f( 1.0, -1.0, 1.0)
glColor3f(col, 0.0,col): glVertex3f(-1.0, -1.0, 1.0)
'Right face
glColor3f(col, 0.0,col): glVertex3f( 1.0, -1.0, -1.0)
glColor3f(col, col,col): glVertex3f( 1.0, 1.0, -1.0)
glColor3f(0.0, col,col): glVertex3f( 1.0, 1.0, 1.0)
glColor3f(0.0, 0.0,col): glVertex3f( 1.0, -1.0, 1.0)
'Left Face
glColor3f(0.0, 0.0,col): glVertex3f(-1.0, -1.0, -1.0)
glColor3f(col, 0.0,col): glVertex3f(-1.0, -1.0, 1.0)
glColor3f(col, col,col): glVertex3f(-1.0, 1.0, 1.0)
glColor3f(0.0, col,col): glVertex3f(-1.0, 1.0, -1.0)
glEnd()
glEndList()
End Sub
Sub draw_cube()
Dim As Single scale = 0.4
Static As Integer theta = 0
gldisable (GL_TEXTURE_2D)
glTranslatef (0.0,0.0,-4.0)
theta = (theta + 1) Mod 360
glRotatef (theta, 0,1,0)
glRotatef (theta, 0,0,1)
glScalef (scale,scale,scale)
init_cube()
End Sub
|
|
|
Nach oben |
|
 |
Jojo alter Rang

Anmeldungsdatum: 12.02.2005 Beiträge: 9736 Wohnort: Neben der Festplatte
|
Verfasst am: 02.03.2010, 18:14 Titel: |
|
|
Du kannst die OpenGL-Bildschirmtextur aus der Grafikkarte "runterladen" und in deinem FB-Screen verwenden, wenn du das meinst.
So kann man den OpenGL-Puffer in Graustufen auslesen. Ich schreibe den Code jetzt nicht um, das kannst du selbst.
PS: Ist Visual Basic-Code, da heißen einige OpenGL-Attribute (rbmBack, pxsPackAlignment) ein wenig anders. Ein wenig DelphiGL-Lesen sollte aber zu Tage bringen, wie die in FB heißen.
Code: | ReDim grayBuffer(lWidth * lHeight) As Byte
'Nur nötig für Graustufen-Umrechnung!
glPixelTransferf pxtRedScale, 0.299 'Grayscale
glPixelTransferf pxtGreenScale, 0.587
glPixelTransferf pxtBlueScale, 0.114
glPixelStoref pxsPackAlignment, 1 'Ohne Padding-Bytes
glReadBuffer rbmBack 'Puffer auswählen
'Pixel reinkopieren: Luminace-Puffer, Format: 8-Bit
glReadPixels 0, 0, lWidth, lHeight, rpLuminance, pxlByte, grayBuffer(0)
'Nur nötig für Graustufen-Umrechnung!
glPixelTransferf pxtRedScale, 1 'Normale Darstellung
glPixelTransferf pxtGreenScale, 1
glPixelTransferf pxtBlueScale, 1 |
_________________ » Die Mathematik wurde geschaffen, um Probleme zu lösen, die es nicht gäbe, wenn die Mathematik nicht erschaffen worden wäre.
 |
|
Nach oben |
|
 |
funkeld gesperrt
Anmeldungsdatum: 10.10.2009 Beiträge: 179
|
Verfasst am: 02.03.2010, 19:14 Titel: |
|
|
Jup, danke.
Gruss
Zuletzt bearbeitet von funkeld am 02.03.2010, 20:55, insgesamt einmal bearbeitet |
|
Nach oben |
|
 |
funkeld gesperrt
Anmeldungsdatum: 10.10.2009 Beiträge: 179
|
Verfasst am: 02.03.2010, 20:54 Titel: |
|
|
Habe dies gefunden im Portal.
Wer kann mir sagen , wie ich dieses in einem Imagepointer einlesen kann mit Freeimage und nicht in einer Datei.
oglbild=ImageCreate(w,h)
Code: |
#INCLUDE ONCE "FreeImage393.bi"
sub TakeScreenshot (filename as STRING)
dim bitmap as FiBitmap ptr
dim FiDataPointer as any ptr
bitmap = FreeImage_Allocate(xres, yres, bits) '// Bild erstellen
FiDataPointer = FreeImage_GetBits(bitmap) '// Pointer auf Bilddaten holen
glReadPixels(0, 0, xres, yres, GL_BGRA, GL_UNSIGNED_BYTE, FiDataPointer) '// Pixel auslesen
FreeImage_Save(FIF_PNG, bitmap, strptr(filename), PNG_DEFAULT) '// Bild als PNG speichern
FreeImage_Unload(bitmap) '// Bild zerstören
end sub
|
|
|
Nach oben |
|
 |
28398
Anmeldungsdatum: 25.04.2008 Beiträge: 1917
|
Verfasst am: 02.03.2010, 21:07 Titel: |
|
|
Hast du doch mit der Funktion. Du musst nur noch in der Zeile wo FreeImage_Save() aufgerufen wird deinen eigenen Kram damit machen.
Ganz nebenbei ist das auch exakt das, was Jojo dir gezeigt hat. Nur langsamer.
Zitat: | Wer kann man helfen, das es in diesem Programm funktioniert? |
Ohne Worte. |
|
Nach oben |
|
 |
funkeld gesperrt
Anmeldungsdatum: 10.10.2009 Beiträge: 179
|
Verfasst am: 02.03.2010, 23:38 Titel: |
|
|
FIF_PNG, bitmap, STRPTR(filename), PNG_DEFAULT
Ich weiss doch nicht, was das Freeimage da haben möchte, damit es in einem Pointer wie bei "imagecreate" reinkommt.
Zur zeit habe ich jetzt stillstand mit dem Einlesen. Klappt nicht.
Gruss |
|
Nach oben |
|
 |
funkeld gesperrt
Anmeldungsdatum: 10.10.2009 Beiträge: 179
|
Verfasst am: 03.03.2010, 00:28 Titel: |
|
|
Mit der sub Screenshot (filename as STRING) kann ich jetzt schon mit dem Tastendruck "W" ein BMP-Bild abspeichern mit Freeimage aus dem Irrlichtfenster.
Anders komme ich nicht weiter.
Gruss
Code: |
#INCLUDE ONCE "FreeImage393.bi"
#include "IrrlichtWrapper.bi"
#include "fbgfx.bi"
#include "GL/gl.bi"
#include "GL/glu.bi"
USING FB
DIM MeshTexture as irr_texture
DIM TestNode as irr_node
Dim TestNode1 as irr_node
DIM OurCamera as irr_camera
Dim shared As String dateiname
sub Screenshot (filename as STRING)
Dim bitmap as FiBitmap ptr
Dim FiDataPointer as any ptr
bitmap = FreeImage_Allocate(399,399, 32) '// Bild erstellen
FiDataPointer = FreeImage_GetBits(bitmap) '// Pointer auf Bilddaten holen
glReadPixels(0, 0, 399,399, GL_BGRA, GL_UNSIGNED_BYTE, FiDataPointer) '// Pixel auslesen
FreeImage_Save(FIF_BMP, bitmap, strptr(filename), BMP_DEFAULT) '// Bild als BMP speichern
FreeImage_Unload(bitmap) '// Bild zerstören
end sub
dateiname="glbild.bmp"
ScreenRes 300,200,32
SCREENCONTROL SET_WINDOW_POS, 10,200
IrrStart( IRR_EDT_OPENGL, 400, 400, IRR_BITS_PER_PIXEL_32, _
IRR_WINDOWED, IRR_NO_SHADOWS, IRR_CAPTURE_EVENTS )
IrrSetWindowCaption( "ogl-bild" )
MeshTexture = IrrGetTexture( "./media/texture.jpg" )
TestNode = IrrAddTestSceneNode
IrrSetNodeMaterialTexture( TestNode, MeshTexture, 0 )
IrrSetNodeMaterialFlag( TestNode, IRR_EMF_LIGHTING, IRR_OFF )
TestNode1 = IrrAddTestSceneNode
IrrSetNodeMaterialTexture( TestNode1, MeshTexture, 0 )
IrrSetNodeMaterialFlag( TestNode1, IRR_EMF_LIGHTING, IRR_OFF )
OurCamera = IrrAddCamera( 0,0,-100, 0,0,0 )
IrrSetNodePosition( OurCamera, 10, 10, -35 )
IrrAddChildToParent( testnode1, testnode)
IrrSetNodePosition( testnode1, 0, 10, 0 )
While IrrRunning
Sleep 1
IrrBeginScene( 255,255,0 )
IrrDrawScene
If multikey( FB.SC_W ) Then
Screenshot(dateiname)
EndIf
IrrEndScene
Wend
IrrStop
|
|
|
Nach oben |
|
 |
28398
Anmeldungsdatum: 25.04.2008 Beiträge: 1917
|
Verfasst am: 03.03.2010, 18:47 Titel: |
|
|
Ich kommentiere NICHT was du geschrieben hast.
Nur nochmal als Denkanstoß:
Zitat: | Hast du doch mit der Funktion. Du musst nur noch in der Zeile wo FreeImage_Save() aufgerufen wird deinen eigenen Kram damit machen. |
Extra in fett. Nur für dich! Ganz exklusiv!
http://downloads.sourceforge.net/freeimage/FreeImage3131.pdf |
|
Nach oben |
|
 |
funkeld gesperrt
Anmeldungsdatum: 10.10.2009 Beiträge: 179
|
Verfasst am: 04.03.2010, 11:59 Titel: |
|
|
Zitat: |
Hast du doch mit der Funktion. Du musst nur noch in der Zeile wo FreeImage_Save() aufgerufen wird deinen eigenen Kram damit machen.
|
Jup, habe ich gemacht.
Gruss |
|
Nach oben |
|
 |
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
|