如何在Python中创建一个OpenGL上下文

2024-10-02 00:22:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用pygame和pyopengl,并试图让glGenTextures(1,img)返回1。我查过了myPixelArt.bmp'有2个维度的幂。从我的脚本开始:

import pygame, OpenGL, math, numpy
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.WGL import *
from OpenGL.GLU import *
from PIL import Image
from ctypes import *

img = Image.open('myPixelArt.bmp')
glEnable(GL_TEXTURE_2D)

hdc=windll.user32.GetDC(1)
print hdc

hglrc=wglCreateContext(hdc)
wglMakeCurrent(hdc,hglrc)
im=glGenTextures(1,img)
print im

但这会为hdc打印0,为im打印0。在

我应该用什么论点windll.user32.GetDC来创建一个显示上下文,并希望让glGenTextures返回1?在


Tags: fromimageimportimgpygameopenglimgl
1条回答
网友
1楼 · 发布于 2024-10-02 00:22:34

尝试先创建一个窗口!在

import pygame, OpenGL, math, numpy
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.WGL import *
from OpenGL.GLU import *
from PIL import Image
from ctypes import *

size=(800,600)
pygame.display.set_mode(size,pygame.OPENGL|pygame.DOUBLEBUF)

img = Image.open('myPixelArt.bmp')
glEnable(GL_TEXTURE_2D)

hdc=windll.user32.GetDC(1)
print hdc

hglrc=wglCreateContext(hdc)
wglMakeCurrent(hdc,hglrc)
im=glGenTextures(1,img)
print im

因为Pygame在窗口中创建了一个OpenGL上下文。在

相关问题 更多 >

    热门问题