hey, I was experimenting with pyglet, and was trying out their opengl, but cant figure out how to scale images... - #!/usr/bin/python
-
-
# $Id:$
-
-
-
-
'''Demonstrates one way of fixing the display resolution to a certain
-
-
size, but rendering to the full screen.
-
-
-
-
The method used in this example is:
-
-
-
-
1. Set the OpenGL viewport to the fixed resolution
-
-
2. Render the scene using any OpenGL functions (here, just a polygon)
-
-
3. Copy the framebuffer into a texture
-
-
4. Reset the OpenGL viewport to the window (full screen) size
-
-
5. Blit the texture to the framebuffer
-
-
-
-
Recent video cards could also render the scene directly to the texture
-
-
using EXT_framebuffer_object. (This is not demonstrated in this example).
-
-
'''
-
-
-
-
from pyglet.gl import *
-
-
from pyglet import clock
-
-
from pyglet import image
-
-
from pyglet import window
-
-
-
-
# Create a fullscreen window using the user's desktop resolution. You can
-
-
# also use this technique on ordinary resizable windows.
-
-
win = window.Window(fullscreen=True)
-
-
-
-
# Use 320x200 fixed resolution to make the effect completely obvious. You
-
-
# can change this to a more reasonable value such as 800x600 here.
-
-
target_resolution = 1280, 800
-
-
-
-
-
class FixedResolutionViewport(object):
-
-
def __init__(self, win, width, height, filtered=False):
-
-
self.window = win
-
-
self.width = width
-
-
self.height = height
-
-
self.texture = image.Texture.create_for_size(GL_TEXTURE_2D,
-
-
width, height, GL_RGB)
-
-
self.texture = self.texture.get_region(0, 0, width, height)
-
-
-
-
if not filtered:
-
-
# By default the texture will be bilinear filtered when scaled
-
-
# up. If requested, turn filtering off. This makes the image
-
-
# aliased, but is more suitable for pixel art.
-
-
glTexParameteri(self.texture.target,
-
-
GL_TEXTURE_MAG_FILTER, GL_NEAREST)
-
-
glTexParameteri(self.texture.target,
-
-
GL_TEXTURE_MIN_FILTER, GL_NEAREST)
-
-
-
-
def begin(self):
-
-
glViewport(0, 0, self.width, self.height)
-
-
self.set_fixed_projection()
-
-
-
-
def end(self):
-
-
buffer = image.get_buffer_manager().get_color_buffer()
-
-
self.texture.blit_into(buffer, 0, 0, 0)
-
-
-
-
glViewport(0, 0, self.window.width, self.window.height)
-
-
self.set_window_projection()
-
-
-
-
aspect_width = self.window.width / float(self.width)
-
-
aspect_height = self.window.height / float(self.height)
-
-
if aspect_width > aspect_height:
-
-
scale_width = aspect_height * self.width
-
-
scale_height = aspect_height * self.height
-
-
else:
-
-
scale_width = aspect_width * self.width
-
-
scale_height = aspect_width * self.height
-
-
x = (self.window.width - scale_width) / 2
-
-
y = (self.window.height - scale_height) / 2
-
-
-
-
glClearColor(0, 0, 0, 1)
-
-
glClear(GL_COLOR_BUFFER_BIT)
-
-
glLoadIdentity()
-
-
glColor3f(1, 1, 1)
-
-
self.texture.blit(x, y, width=scale_width, height=scale_height)
-
-
-
-
def set_fixed_projection(self):
-
-
# Override this method if you need to change the projection of the
-
-
# fixed resolution viewport.
-
-
glMatrixMode(GL_PROJECTION)
-
-
glLoadIdentity()
-
-
glOrtho(0, self.width, 0, self.height, -1, 1)
-
-
glMatrixMode(GL_MODELVIEW)
-
-
-
-
def set_window_projection(self):
-
-
# This is the same as the default window projection, reprinted here
-
-
# for clarity.
-
-
glMatrixMode(GL_PROJECTION)
-
-
glLoadIdentity()
-
-
glOrtho(0, self.window.width, 0, self.window.height, -1, 1)
-
-
glMatrixMode(GL_MODELVIEW)
-
-
-
-
rotate = 0
-
kitten = image.load('kitten.jpg')
-
-
def draw_scene():
-
global kitten
-
-
# Draw the scene, assuming the fixed resolution viewport and projection
-
-
# have been set up.
-
-
glClearColor(0, 0, 0, 0)
-
-
glClear(GL_COLOR_BUFFER_BIT)
-
f=kitten.width
-
-
glLoadIdentity()
-
glEnable(GL_TEXTURE_2D)
-
-
w, h = target_resolution
-
-
glTranslatef(w/2, h/2, 0)
-
-
glRotatef(rotate, 0, 0, 1)
-
-
#glColor3f(1, 1, 0,)
-
-
s = min(w, h) / 4
-
-
glRectf(s, s, s, s)
-
kitten.blit(0,0)
-
-
viewport = FixedResolutionViewport(win,
-
-
target_width, target_height, filtered=False)
-
-
while not win.has_exit:
-
-
dt = clock.tick()
-
-
rotate += dt * 20
-
-
-
-
win.dispatch_events()
-
-
-
-
viewport.begin()
-
-
win.clear()
-
-
draw_scene()
-
-
viewport.end()
-
-
-
-
win.flip()
that is the fixed_resolutio n.py file that came with it
basically i just want to make that kitten picture rotate instead of the red box. i got the picture to rotate, but I cant figure out how to scale it down to match the box size.
i searched for about 2-3 hours tonight for opengl refrences on how to do this but came up empty handed
1 4212
Oops, embarrassing... I put down the wrong code :p - kitten = image.load('kitten.jpg')
-
texture=kitten.texture
-
-
def draw_scene():
-
global kitten, texture
-
-
# Draw the scene, assuming the fixed resolution viewport and projection
-
-
# have been set up.
-
-
glClearColor(0, 0, 0, 0)
-
-
glClear(GL_COLOR_BUFFER_BIT)
-
f=kitten.width
-
-
glLoadIdentity()
-
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
-
glEnable(GL_TEXTURE_2D)
-
-
w, h = target_resolution
-
-
glTranslatef(w/2, h/2, 0)
-
-
#glRotatef(rotate, 0, 0, 1)
-
-
glColor3f(1, 0, 1)
-
-
s = min(w, h) / 4
-
-
glRectf(-s, -s, s, s)
-
glBindTexture(GL_TEXTURE_2D, texture.id)
-
glBegin(GL_POLYGON)
-
glVertex3f (-s, -s, 0.0);
-
glVertex3f (s, -s, 0.0);
-
glVertex3f (s, s, 0.0);
-
glVertex3f (-s, s, 0.0);
-
glEnd()
that is what I changed, and all it gives is a gray square
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jg.campbell.ng |
last post by:
I'm beginning learning Python and OpenGL in Python.
Python fine. But difficulties with OpenGL; presumably with the
installation of OpenGL.
OS = Linux FC5.
Python program gl_test.py:
from OpenGL.GLUT import *
|
by: morris.slutsky |
last post by:
So every now and then I like to mess around with hobby projects - I
often end up trying to write an OpenGL video game. My last attempt
aborted due to the difficulty of automating game elements and creating
a good level editor - I basically needed a scripting language to
control the C modules of the game and, after a half-assed attempt or
two to make my own, I just gave up. So naturally this seems like a job
for Python. Embedding Python...
|
by: imx |
last post by:
Hi there,
I wonder whether python can be used to simulate a real user to do the
following:
1) open a web site in a browser;
2) printscreen, so to copy the current active window image to
clipboard;
3) save the image file to a real file
Any pointer will be apprieciated!
|
by: PatrickMinnesota |
last post by:
I like to do fun stuff when learning a new language. I've been
working with Python for a little while on real world problems mostly
fixing bugs and writing a simulator for work.
I was thinking as a hobby project developing a simple 2d game (think
Donkey Kong, Space Invaders, LoadRunner) and mentioned this to my 14
year old nephew. About a week later I got a full write up for a game
that he wrote and would like to play. So I figure why...
|
by: Facundo Batista |
last post by:
Hi!
This post is to tell you about a Python event we had the last weekend.
It was a Python camping, in Los Cocos, Córdoba, Argentina. More than
20 Python developers, some experienced, some new ones, joined together
in a center where we made a lot of activities during four whole days:
- We had a mini python bug day, closing 4 or 5 issues, but more
important, two new developers know how the full process is.
| |
by: _wolf |
last post by:
cairo@cairographics.org]
hi all,
i've heard cairo has become the image scling library for firefox3. is
that true? wonderful, i want to do that in python. there's a python
interface for cairo, right? i've used it before to do simple vector
stuff. seems to work. however, i haven't been able to find relevant
pointers via google.
|
by: david |
last post by:
You learn something new every day:
On my ubuntu, update-manager is supposed to use the python2.5
installed on /usr/bin. Well, I had subsequently installed a whole
bunch of stuff in /usr/local (/usr/local/bin/python and /usr/local/lib/
python2.5 etc), which I have happily been using for development for a
year. I had thought that the two pythons were completely independent.
Well, I was wrong. When /usr/bin/python2.5 runs, *by default*,...
|
by: Thomas Troeger |
last post by:
Hi,
Sorry I've posted a similar question some weeks ago, but I got no
answers. I want to embed a Python application on a device with limited
resources, esp. storage limitations. Is there a way to reduce the Python
interpreter to a set of modules that's urgently needed? Or is there a
method to have gzipped modules that are unzipped on the fly into memory
when they're accessed? That would be even better.
Additionally, is there a Python...
|
by: Ben Sizer |
last post by:
Although the standard library in Python is great, there are
undoubtedly some great packages available from 3rd parties, and I've
encountered a few almost by accident. However, I don't know how a user
would become aware of many of these. http://pypi.python.org/pypi/
presumably lists most of the decent ones, but there's a lot there and
little indication as to quality or popularity - great if you know
exactly what you need, but not so great...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |