Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Cheery

Pages: [1]
1
General discussions / OpenGL 4
« on: February 05, 2011, 06:59:39 pm »
Still too early to talk about opengl4 support?

2
Graphics / Easy approach
« on: January 11, 2011, 06:23:47 pm »
I found this easy approach: I'll output pngs numbered from 0 upwards and then use ffmpeg to convert it into video.

This is working for my current screen scraping needs. Though a friend said that if I ever want to avoid jitter, I should either get help from GPU at video encoding or then make an unencoded flatfile. He also said that I'd need to pick 60fps images and interpolate them down to 30fps to get smooth, nice high-definition video.

The video class in wiki seems to bother only with decoding video. I don't know how to apply that one to encoding and saving videos.

There's another question I've got: where the heck ffmpeg keeps its documentation about libavcodec and such? I only found something about decoding videos with those. Didn't tell how to encode. :?

3
Graphics / Video capture
« on: January 10, 2011, 10:09:07 am »
Linux has terrible screen scraping availability so I'd like to implement one directly into my program.

You only allow screenshots, though would there be a way to construct video out of them through some library?

4
Python / Nevermind
« on: January 08, 2011, 07:21:52 pm »
I just decided to drop sprites and applied little bit of opengl.

Code: [Select]
# -*- coding: utf-8 -*-
from PySFML import sf
from OpenGL.GL import (
    glBegin,
    glDisable,
    glEnd,
    glTexCoord2f,
    glTranslatef,
    glVertex2f,
    GL_TEXTURE_2D,
    GL_QUADS,
)

class Patch(sf.Drawable):
    def __init__(self, image):
        sf.Drawable.__init__(self)
        self.SetImage(image)
   
    def SetImage(self, image):
        self.image = image
        width = image.GetWidth()
        height = image.GetHeight()
        for x in range(1, width):
            if image.GetPixel(x, 0).a > 0:
                right = x + 1
            if image.GetPixel(width - x, 0).a > 0:
                left = width - x
        for y in range(1, height):
            if image.GetPixel(0, y).a > 0:
                bottom = y + 1
            if image.GetPixel(0, height - y).a > 0:
                top = height - y
        row = 1, left, right, width
        col = 1, top, bottom, height
        self.borders = top-1, height-bottom, left-1, width-right
        self.subrects = [
            sf.IntRect(
                row[i%3],
                col[i/3],
                row[i%3+1],
                col[i/3+1],
            )
            for i in range(9)
        ]
        self.width = width
        self.height = height

    def Resize(self, width, height):
        self.width = width
        self.height = height

    def Render(self, target):
        image = self.image
        width = self.width
        height = self.height
        top, bottom, left, right = self.borders
        row = [0, left, self.width-right, self.width]
        col = [0, top, self.height-bottom, self.height]

        if image and image.GetWidth() and image.GetHeight():
            image.Bind()
            for i, subrect in enumerate(self.subrects):
                x = i%3
                y = i/3
                rect = image.GetTexCoords(subrect)
                glBegin(GL_QUADS)
                glTexCoord2f(rect.Left,  rect.Top);    glVertex2f(row[x],   col[y])
                glTexCoord2f(rect.Left,  rect.Bottom); glVertex2f(row[x],   col[y+1])
                glTexCoord2f(rect.Right, rect.Bottom); glVertex2f(row[x+1], col[y+1])
                glTexCoord2f(rect.Right, rect.Top);    glVertex2f(row[x+1], col[y])
                glEnd()
        else:
            glBegin(GL_QUADS)
            glVertex2f(0,     0)
            glVertex2f(0,     height)
            glVertex2f(width, height)
            glVertex2f(width, 0)
            glEnd()

5
Python / Subclassing Drawable
« on: January 08, 2011, 06:02:50 pm »
I wanted to draw 9-patches so I created a class for it by subclassing Drawable so it'd work like usual sprites.

Only later I noticed there's lots of methods for doing transformations with the drawable. How to get them affect my sprite patch?

Code: [Select]
# -*- coding: utf-8 -*-
from PySFML import sf

class Patch(sf.Drawable):
    def __init__(self, image):
        sf.Drawable.__init__(self)
        self.image = image
        width = image.GetWidth()
        height = image.GetHeight()
        for x in range(1, width):
            if image.GetPixel(x, 0).a > 0:
                right = x + 1
            if image.GetPixel(width - x, 0).a > 0:
                left = width - x
        for y in range(1, height):
            if image.GetPixel(0, y).a > 0:
                bottom = y + 1
            if image.GetPixel(0, height - y).a > 0:
                top = height - y
        row = 1, left, right, width
        col = 1, top, bottom, height
        self.sprites = [sf.Sprite(image) for _ in range(9)]
        self.borders = top-1, height-bottom, left-1, width-right
        for i in range(9):
            x, y = i % 3, i / 3
            rect = sf.IntRect(
                row[x],
                col[y],
                row[x+1],
                col[y+1]
            )
            self.sprites[i].SetSubRect(rect)
        self.position = 0, 0
        self.Resize(width, height)

    def Resize(self, width, height):
        self.width = width
        self.height = height
        top, bottom, left, right = self.borders
        row = [left, width - left - right, right]
        col = [top, height - top - bottom, bottom]
        for i in range(9):
            x, y = i % 3, i / 3
            self.sprites[i].Resize(row[x], col[y])
        self.SetPosition(*self.position)

    def SetPosition(self, x, y):
        self.position = x, y
        top, bottom, left, right = self.borders
        row = [x, x+left, x+self.width-right]
        col = [y, y+top, y+self.height-bottom]
        for i in range(9):
            x, y = i % 3, i / 3
            self.sprites[i].SetPosition(row[x], col[y])

    def Render(self, target):
        for sprite in self.sprites:
            target.Draw(sprite)

Pages: [1]