OpenGL game screen capture
Problem is solved, I just calling GetScreenData(...)
before SwapBuffers(...)
now it works correctly but there is still a weird thing, on some computers I'v got shifted screens, for example: Screen #1 Don't know why it happens, for sure it happens on Nvidia 5xxx(m) i 7xxx(m) series so far as I know.
Big thanks for @AndonM.Coleman
Regular window screen capture using openGL
What you're asking for is something completely outside the scope of OpenGL. OpenGL is designed to be a platform-agnostic API for applications to talk about drawing stuff into framebuffers in an abstract fashion. OpenGL has no notion of windows*, screens, or a desktop. OpenGL doesn't operate at a level where such concepts exist. Heck, OpenGL doesn't even know what a GPU is. OpenGL is supposed to be initialized through platform-specific mechanisms to establish a context which assigns actual meaning to OpenGL API calls. As far as I know, there is no way to set up an OpenGL context with a framebuffer whose contents would somehow correspond to the desktop on Windows (or any other platform I'm aware of). As far as my understanding goes, this wouldn't really make sense…
To do what you want to do, you'll have to rely on the respective platform-specific APIs. The probably simplest way on Windows is to get an HDC for the entire desktop and BitBlt from there. See, e.g., this question for more on that. A more modern approach would be to use the DXGI Desktop Duplication API.
(*) yes, I know the OpenGL specification technically does talk about "windows" in a few places; but it only really does so when it's talking about all the things it's not responsible for…
Screenshots in OpenGL using python
Read the framebuffer with glReadPixels
before the display is updated (before pygame.display.flip()
or pygame.display.update()
). Use pygame.image.fromstring()
to create new Surfaces from the buffer. Finally, save the Surface to a file:
def main():
# [...]
while True:
screenshot = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_s:
screenshot = True
glRotatef(1, 12, 0,55115 )
for i in range(8):
s=[]
for j in verticies[i]:
s.append([j])
k=zarb_matris(s,a)
verticies[i]=k
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Cube()
if screenshot:
screen = pygame.display.get_surface()
size = screen.get_size()
buffer = glReadPixels(0, 0, *size, GL_RGBA, GL_UNSIGNED_BYTE)
screen_surf = pygame.image.fromstring(buffer, size, "RGBA")
pygame.image.save(screen_surf, "screenshot.jpg")
pygame.display.flip()
pygame.time.wait(10)
Related Topics
Restrict Variadic Template Arguments
Finding Square Root Without Using Sqrt Function
Broken C++ Std Libraries on MACos High Sierra 10.13
Pros & Cons of Putting All Code in Header Files in C++
Why Is There No 2-Byte Float and Does an Implementation Already Exist
Simpler Way to Create a C++ Memorystream from (Char*, Size_T), Without Copying the Data
Deciphering C++ Template Error Messages
Align Cout Format as Table's Columns
Cost of Throwing C++0X Exceptions
Changing Dpi Scaling Size of Display Make Qt Application's Font Size Get Rendered Bigger
C++ Best Way to Get Integer Division and Remainder
What Is the Branch in the Destructor Reported by Gcov
What Is the Meaning of Template<> with Empty Angle Brackets in C++
Eclipse C++:"Program "G++" Not Found in Path"
Is Writing to &Str[0] Buffer (Of a Std:String) Well-Defined Behaviour in C++11