Don Polettone
Don Polettone

Reputation: 195

blitting pygame.Surface() onto pygame.OPENGL display

How can I blit a pygame.Surface() object onto a pygame.OPENGL display and flip the display?

import pygame

pygame.init()

RES = (640, 480)
display = pygame.display.set_mode(RES, pygame.FULLSCREEN | pygame.OPENGL)

bg_img = pygame.Surface(RES)
bg_img.fill((255, 255, 255))

display.blit(bg_img, (0, 0))
pygame.quit()
sys.exit()

gives me

Traceback (most recent call last):
  File "C:/Game Dev/TESTS/Clock Comparison/opengl_test.py", line 12, in <module>
    display.blit(bg_img, (0, 0))
error: Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)

Upvotes: 2

Views: 4303

Answers (1)

user748622
user748622

Reputation: 21

You cannot. To avoid the error, the display surface needs to use the pygame.OPENGLBLIT flag instead of the pygame.OPENGL flag, however after running code like this:

import pygame
import sys

pygame.init()

RES = (640, 480)
display = pygame.display.set_mode(RES, pygame.OPENGLBLIT)

bg_img = pygame.Surface(RES).
bg_img.fill((255, 255, 255))

display.blit(bg_img, (0, 0))
pygame.display.flip()
input()
pygame.quit()
sys.exit()

the display window remains blank.

The pygame documentation lists this flag as:

create an OpenGL rendering context / and use it for blitting. Obsolete.

You will need to find a way to do whatever you were trying in pyOpenGL itself instead.

Upvotes: 2

Related Questions