You are not logged in.
I ran some test while I was thinking, and the GIMP method will be too slow. I'm on a AMD 6400+ processor (3200Mhz), 4GB DDR2 RAM, and SATA 3.0 hardrives, and for an image that was around 600x800 it took 4 four seconds. The transform itself seems to be pretty fast, but then there's the overhead of file IO and swapping images in and out of memory. If performance is key, bwalk's idea of using OpenGL is probably the best solution.
Last edited by skottish (2008-10-04 18:16:14)
Offline
I see.
I'm on an Intel P4 (2600MHz), 512MB DDR-266 RAM, and an IDE HDD. I have a 133MHz FSB, while most systems' are 500-900MHz+. So if it took 4 seconds there, it'd make sense that 3Drotate took 30 seconds here!
Maybe we should drop this until I have new hardware.
-dav7
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
This may actually still work. I did some refining of my test script, and I'm able to process six 800x600 PNG files in 5.4 seconds. This includes the time it takes to start GIMP. I removed the 'n' flag out of the command line also; I forgot it was there to help fight a memory leak that I had in one of my Scheme scripts (user error). One of the things I was thinking about was that you'll probably only need one image in memory anyway and that will reduce times significantly.
Do me a favor and try this script using six 800x600 PNG files. It will not overwrite the files; They will be saved as trans_000001.png to trans_000006.png. It's called trans.py and is invoked with the 'time' function by:
time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)'
Note: The transform values below are arbitrary. I just plugged numbers in for testing. The function's processing time varies depending on the values used, so this is only a rough estimate.
#! /usr/bin/env python
from gimpfu import *
import glob
def trans(file_pattern):
count=1
file_list=glob.glob(file_pattern)
for file_name in file_list:
image = pdb.gimp_file_load(file_name, file_name)
drawable = pdb.gimp_image_get_active_layer(image)
drawable = pdb.gimp_drawable_transform_perspective(drawable, 31, 58, 522, 130, 0.798, 800, 560, 678, 0, 1, False, 3, 1)
pdb.gimp_file_save(image, drawable, "trans_" + str(count).zfill(6) + ".png", "trans_" + str(count).zfill(6) + ".png" )
pdb.gimp_image_delete(image)
count+=1
register(
"trans", "", "", "", "", "",
"<Toolbox>/Filters/Python-Fu/_trans", "",
[
(PF_STRING, "file_suffix", "file_suffix", "file_suffix")
],
[],
trans
)
main()
Last edited by skottish (2008-10-05 16:00:41)
Offline
Hang on, let me find 6 old screenshots.
-dav7
Last edited by dav7 (2008-10-05 16:46:21)
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Don't you think ~1sec/pic is a bit slow? You can do perspective transformation in realtime.
Offline
Done, after examining a small subsection of a 11,974 line output for "grep '.bmp' listing | wc -l" from an already-generared listing file and converting these BMPs to PNGs, time to play
bwalk: How? Could you post a demo - however rudimentary, I'd test it.
-dav7
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Okay, we has errorz
I put the script (levels.py) in ~/.gimp-2.5/plug-ins/ which I've confirmed just now is indeed a recognized plugin path (the only other is in /usr), and ran the command from the directory I had my PNGs in
Look out for my ##- or #'d comments:
time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)'
This is a development version of GIMP. Debug messages may appear here.
/usr/lib/gimp/2.0/plug-ins/help-browser: error while loading shared libraries: libwebkit-1.0.so.1: cannot open shared object file: No such file or directory
(gimp:22383): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
batch command experienced an execution error
^Cgimp: terminated: Interrupt ## Note that I hit ^C at this point
real 0m31.301s
user 0m1.637s
sys 0m0.427s
/Users/dav7/pix2/ + /usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
(script-fu:22390): LibGimp-WARNING **: script-fu: gimp_flush(): error: Broken pipe
/Users/dav7/pix2/ + time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)' # try again :D
This is a development version of GIMP. Debug messages may appear here.
/usr/lib/gimp/2.0/plug-ins/help-browser: error while loading shared libraries: libwebkit-1.0.so.1: cannot open shared object file: No such file or directory
(gimp:22420): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
batch command experienced an execution error
^Cgimp: terminated: Interrupt # quit... again...
real 0m13.104s
user 0m1.707s
sys 0m0.360s
/usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
(script-fu:22424): LibGimp-WARNING **: script-fu: gimp_flush(): error: Broken pipe
/Users/dav7/pix2/ +
/Users/dav7/pix2/ +
/Users/dav7/pix2/ + time gimp -ibdf '(python-fu-trans RUN-INTERACTIVE "*.png")''(gimp-quit 1)' # "Why not try INTERACTIVE?"...
This is a development version of GIMP. Debug messages may appear here.
/usr/lib/gimp/2.0/plug-ins/help-browser: error while loading shared libraries: libwebkit-1.0.so.1: cannot open shared object file: No such file or directory
(gimp:22435): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
batch command experienced an execution error
^Cgimp: terminated: Interrupt # nope...
real 0m5.506s
user 0m1.627s
sys 0m0.430s
/usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
(script-fu:22439): LibGimp-WARNING **: script-fu: gimp_flush(): error: Broken pipe
/Users/dav7/pix2/ +
/Users/dav7/pix2/ +
/Users/dav7/pix2/ + time gimp -ibdf '(python-fu-trans RUN-INTERACTIVE "*.png")' # hm, what about not making it quit?
This is a development version of GIMP. Debug messages may appear here.
/usr/lib/gimp/2.0/plug-ins/help-browser: error while loading shared libraries: libwebkit-1.0.so.1: cannot open shared object file: No such file or directory
(gimp:22447): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
batch command experienced an execution error
^Cgimp: terminated: Interrupt # nope.
real 0m9.251s
user 0m1.593s
sys 0m0.400s
/usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
(script-fu:22451): LibGimp-WARNING **: script-fu: gimp_flush(): error: Broken pipe
/Users/dav7/pix2/ +
/Users/dav7/pix2/ +
/Users/dav7/pix2/ + # D:
-dav7
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Don't you think ~1sec/pic is a bit slow? You can do perspective transformation in realtime.
As I pointed out, I pulled the frames from the disk and used Python's glob pattern before I saved them the images. The first two operations are there for testing purposes only. The transform itself can be done practically in real time including drawing to screen in GIMP's UI as seen by the transform editing window. One of the criteria is to save each iteration as a PNG file; That will remain a bit of a performance hit regardless how the images are generated.
With that being said, I have no doubt that your solution would be faster, quite a bit more elegant, and perform better in memory. I'm just trying to help with what I know.
dav7,
I don't know if missing libwebkit is what's cause the script to fail or not. My best guess here is that I'm using GIMP 2.6.0. Unfortunately GIMP errors are cryptic as hell. Scheme is far worse than Python though when it comes to GIMP.
Offline
Oh. 2.6 isn't anywhere nearby in binary format is it?
-dav7
Last edited by dav7 (2008-10-05 17:31:59)
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
It's under gimp-devel in Arch right now. Just pacman -S gimp-devel (and possibly libwebkit). Why the regular version hasn't been updated is beyond me; They're the same program.
Since GIMP is designed to allow more than one version, it will store all personal settings in ~/.gimp-2.6. I use a separate Python directory for my scripts just to keep them organized.
Last edited by skottish (2008-10-05 17:47:46)
Offline
Whoa whoa whoa whoa whoa. Something is majorly weird here.
* Package listing lists gimp at 2.4.7-1.
* Package listing lists gimp-devel at 2.6.0-1.
* Whatever I have installed that looks like the "new" GIMP has the version 2.5.3 in the About box?!
These version numbers are confusing me
And, I have gimp-devel installed. I just accidentally removed and reinstalled it, and ooh, now it doesn't say 2.5.3 in the About box.
Okay, so gimp-devel is version 2.6, but it's saying it's looking in ~/.gimp-2.6/plug-ins/... it was looking in 2.5 before, let me move my script over.
Lastly, to confuse the confusion, I'd get gimp-2.5 before the reinstall when I hit gimp<tab>, now I get gimp-2.6. :s
At any rate, the dialog box doesn't say "This is an unstable development release." anymore.
Take two.
-dav7
Last edited by dav7 (2008-10-05 18:06:15)
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Hmmm? I think Wilber may be smoking a bit of that Aussie grass! It's reporting 2.6 here.
Offline
Okay, with GIMP 2.6 and WebKit installed, I get this wonderfully informative info when I run the command.
/Users/dav7/pix2/ + time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)'
batch command experienced an execution error
^Cgimp: terminated: Interrupt
real 0m8.247s
user 0m1.407s
sys 0m0.390s
/usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
/Users/dav7/pix2/ +
(script-fu:27035): LibGimp-WARNING **: script-fu: gimp_flush(): error: Broken pipe
/Users/dav7/pix2/ +
Of course, the ^C you see above is me ^Cing the process.
I kept htop open while the script ran and CPU usage hit 100% while it was processing *very* briefly (the error message appears pretty quickly), it dropped down to 14.1% or so.
Do you want to ssh and give this a spin that way?
-dav7
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
ssh won't be necessary. GIMP's not finding the images. Try to change the line to:
time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "/Users/dav7/pix2/*.png")''(gimp-quit 1)'
Offline
Nope
/Users/dav7/ + cd pix2
/Users/dav7/pix2/ + time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "/Users/dav7/pix2/*.png")''(gimp-quit 1)'
batch command experienced an execution error
^Cgimp: terminated: Interrupt
real 0m13.921s
user 0m1.637s
sys 0m0.423s
/usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
(script-fu:29477): LibGimp-WARNING **: script-fu: gimp_flush(): error: Broken pipe
/Users/dav7/pix2/ + ls
total 388K
drwxr-xr-x 2 dav7 64 2008-10-06 03:42 x
-rw-r--r-- 1 dav7 3.5K 2008-10-06 03:42 00_1.png
-rw-r--r-- 1 dav7 34K 2008-10-06 03:42 oddExplorer.png
-rw-r--r-- 1 dav7 15K 2008-10-06 03:42 old run.png
-rw-r--r-- 1 dav7 23K 2008-10-06 03:42 pic1.png
-rw-r--r-- 1 dav7 120K 2008-10-06 03:42 scr.png
-rw-r--r-- 1 dav7 83K 2008-10-06 03:42 winmedia-09.png
-rw-r--r-- 1 dav7 47K 2008-10-06 03:42 winmedia10.png
-rw-r--r-- 1 dav7 49K 2008-10-06 03:42 xmplay02.png
/Users/dav7/pix2/ + mv o
oddExplorer.png old run.png
/Users/dav7/pix2/ + mv old{\ ,_}run.png
/Users/dav7/pix2/ + ls
total 388K
drwxr-xr-x 2 dav7 64 2008-10-06 03:42 x
-rw-r--r-- 1 dav7 3.5K 2008-10-06 03:42 00_1.png
-rw-r--r-- 1 dav7 34K 2008-10-06 03:42 oddExplorer.png
-rw-r--r-- 1 dav7 15K 2008-10-06 03:42 old_run.png
-rw-r--r-- 1 dav7 23K 2008-10-06 03:42 pic1.png
-rw-r--r-- 1 dav7 120K 2008-10-06 03:42 scr.png
-rw-r--r-- 1 dav7 83K 2008-10-06 03:42 winmedia-09.png
-rw-r--r-- 1 dav7 47K 2008-10-06 03:42 winmedia10.png
-rw-r--r-- 1 dav7 49K 2008-10-06 03:42 xmplay02.png
/Users/dav7/pix2/ + ls
total 388K
drwxr-xr-x 2 dav7 64 2008-10-06 03:42 x
-rw-r--r-- 1 dav7 3.5K 2008-10-06 03:42 00_1.png
-rw-r--r-- 1 dav7 34K 2008-10-06 03:42 oddExplorer.png
-rw-r--r-- 1 dav7 15K 2008-10-06 03:42 old_run.png
-rw-r--r-- 1 dav7 23K 2008-10-06 03:42 pic1.png
-rw-r--r-- 1 dav7 120K 2008-10-06 03:42 scr.png
-rw-r--r-- 1 dav7 83K 2008-10-06 03:42 winmedia-09.png
-rw-r--r-- 1 dav7 47K 2008-10-06 03:42 winmedia10.png
-rw-r--r-- 1 dav7 49K 2008-10-06 03:42 xmplay02.png
/Users/dav7/pix2/ + time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "/Users/dav7/pix2/*.png")''(gimp-quit 1)'
batch command experienced an execution error
^Cgimp: terminated: Interrupt
real 0m5.040s
user 0m1.583s
sys 0m0.417s
/usr/lib/gimp/2.0/plug-ins/script-fu terminated: Interrupt
(script-fu:29484): LibGimp-WARNING **: script-fu: gimp_flush(): error: Broken pipe
/Users/dav7/pix2/ +
Transcription:
*run*
":S"
*copy listing to show that there are actually PNGs in here*
"ooh, maybe that space is making it stuff up"
*rename*
*run*
*:S*
"nope."
*give up*
-dav7
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Eeeeekkkk! I thought that your terminal prompt was part of a command. I guess I've been dipping into Wilber's stash...
I can't believe that I didn't think of this before. Did you make the Python script executable? If not, do so:
chmod +x trans.py
The run it with:
gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)'
in the directory of the test files.
Last edited by skottish (2008-10-06 04:26:42)
Offline
As I pointed out, I pulled the frames from the disk and used Python's glob pattern before I saved them the images. The first two operations are there for testing purposes only. The transform itself can be done practically in real time including drawing to screen in GIMP's UI as seen by the transform editing window. One of the criteria is to save each iteration as a PNG file; That will remain a bit of a performance hit regardless how the images are generated.
With that being said, I have no doubt that your solution would be faster, quite a bit more elegant, and perform better in memory. I'm just trying to help with what I know.
I'm sorry, I don't wanted to be rude or offend you. My comment sound more harsh then intended. I appologize.
bwalk: How? Could you post a demo - however rudimentary, I'd test it.
I would, in theory, load the image into an OpenGL texture, bind that texture to a simple primitive (rectangle) and then perform the simple transformations on the primitive and let the gpu take care of the rest. Said that, I can not give you sample code, as it needs a bit time I can't afford right now and I can only code this in C, which you sadly dislike. Put if you like python, I herad the pyhton binding for OpenGL is quite nice and simple.
On the other hand, you might look into convert and the rest of imagemagick's fine binaries. It can do basic transformations too.
Offline
to be honest, how about you look into doing this "properly" and really make an effort. Using workaround ways like this is just going to take time and produce disappointing results.
IMHO, spend a little money, get K&R, The C Programming Language. Dirt cheap on www.abebooks.com, got mine for 15AUD including shipping. After that, there's a few books on OpenGL.
Think of how much more you'll be capable of in the longer term. While messing about with python and gimp seems fun and while it might work, in the longer term - C and the options it will bring is so much more effective.
I've decided to do this too. My K&R copy arrived last week, and I'll get down to learning it properly after my exams. I did learn it many years ago, but never used it so it slipped...
It's frustrating, you hit walls, you spend hours on a silly little bug, but when you do work it out and get something that works, the reward is great.
Last edited by iphitus (2008-10-06 10:11:29)
Offline
Eeeeekkkk! I thought that your terminal prompt was part of a command. I guess I've been dipping into Wilber's stash...
I can't believe that I didn't think of this before. Did you make the Python script executable? If not, do so:
chmod +x trans.py
The run it with:
gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)'
in the directory of the test files.
IT LIVES!!!
But.
This is with 8 PNGs:
/Users/dav7/pix2/ + time gimp -ibdf '(python-fu-trans RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)'
real 0m43.642s
user 0m26.818s
sys 0m1.607s
That's 72.067 seconds, or 1 minute, 12 seconds.
I give up I have too slow a PC to do this
...
dav7 wrote:bwalk: How? Could you post a demo - however rudimentary, I'd test it.
I would, in theory, load the image into an OpenGL texture, bind that texture to a simple primitive (rectangle) and then perform the simple transformations on the primitive and let the gpu take care of the rest. Said that, I can not give you sample code, as it needs a bit time I can't afford right now and I can only code this in C, which you sadly dislike. Put if you like python, I herad the pyhton binding for OpenGL is quite nice and simple.
On the other hand, you might look into convert and the rest of imagemagick's fine binaries. It can do basic transformations too.
I'm starting to slowly not dislike C. Pointers aren't as scary as they were before. So a C example would be taken with some trepidation, but not run away from, at this point. However, since we're all busy, I respect you have no time and that's absolutely fine - no offense intended or taken.
to be honest, how about you look into doing this "properly" and really make an effort. Using workaround ways like this is just going to take time and produce disappointing results.
I'd like to, but to me, this is my best at the moment.
IMHO, spend a little money, get K&R, The C Programming Language. Dirt cheap on www.abebooks.com, got mine for 15AUD including shipping. After that, there's a few books on OpenGL
I don't have the mental abilities to appreciate a book, however well written it is, right now.
Think of how much more you'll be capable of in the longer term. While messing about with python and gimp seems fun and while it might work, in the longer term - C and the options it will bring is so much more effective.
I agree.
I've decided to do this too. My K&R copy arrived last week, and I'll get down to learning it properly after my exams. I did learn it many years ago, but never used it so it slipped...
It's frustrating, you hit walls, you spend hours on a silly little bug, but when you do work it out and get something that works, the reward is great.
True, it IS frustrating. I've cried. And you do hit walls - I've been hitting the wall of pointers for the last however many months. Yeah, I've spent "hours" (months) on the bug of my brain not understanding pointers. But I've been (with Help) slowly working it out, and getting something that works. And yes, the reward - mental access to the most popular language out there, with bindings to and for everything - will be AWESOME
-dav7
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Ok, I found some sample from *the* only book for opengl, the opengl redbook. Read and understand this, there is nothing more to opengl.
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
/* Create checkerboard texture */
#define checkImageWidth 64
#define checkImageHeight 64
static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
static GLuint texName[1];
/* here goes your routine to load the image into the texture */
void makeCheckImages(void)
{
int i, j, c;
for (i = 0; i < checkImageHeight; i++) {
for (j = 0; j < checkImageWidth; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
checkImage[i][j][3] = (GLubyte) 255;
}
}
}
/* just some setup stuff for opengl */
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeCheckImages();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, texName);
glBindTexture(GL_TEXTURE_2D, texName[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
checkImage);
glEnable(GL_TEXTURE_2D);
}
/*
* this actually displays stuff on the screen, it draws a rectangle containing
* the generated/loaded texture.
*/
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texName[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
glEnd();
glFlush();
}
/* here your perspective transformation goes into */
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0); /* see? */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -3.6);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}
Don't bother to understand this, took me two fulltime courses at university. Compile with this
cc texbind2.o -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm -o texbind2
freeglut dependend.
This is just to show you how simple such a program can be. There is nothing scary about this, the program don't uses a single pointer, which are overrated anyways.
Study K&R, study the redbook and then study some code, some good code, the most important thing.
Offline
bwalk: It compiles, but... uuhh... I can actually quasi-understand that, to the point that I expect some kind of perspective transformation to occur, which doesn't.
I see:
Is that what I'm supposed to be seeing?
-dav7
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Yeah, it's just one frame with the given (honestly not so fancy) perspective. But you can easily apply any regular transformation on it by modifying the projection matrix (in this code, try modifying some parameters of gluPerspective). So you can dynamically generate perspectives somehow and rerender the scene, resulting in an animation.
Offline
bwalk:
After a LOT of modification and a bit of googling... what FUN! No, no perspective transformations or 3D, but... meh
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
/* Create checkerboard texture */
#define checkImageWidth 64
#define checkImageHeight 64
static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
static GLuint texName[1];
float distance = -180;
float delta = 4.0;
int xpos = 0, ypos = 0, ydelta = 2, xdelta = 1;
/* here goes your routine to load the image into the texture */
void makeCheckImages(void)
{
int i, j, c;
for (i = 0; i < checkImageHeight; i++) {
for (j = 0; j < checkImageWidth; j++) {
c = ((((i & 0x8) == 0) ^ ((j & 0x8)) == 0)) * rand();
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
checkImage[i][j][3] = (GLubyte) 255;
}
}
}
void renderchecker(void) {
makeCheckImages();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
checkImage);
}
/* just some setup stuff for opengl */
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, texName);
glBindTexture(GL_TEXTURE_2D, texName[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
renderchecker();
glEnable(GL_TEXTURE_2D);
}
/* here your perspective transformation goes into */
void reshape(int w, int h)
{
glViewport(xpos, ypos, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(distance, 1, 1.0, 4.0); /* see? */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(1.0, 0.0, -2.6);
}
/*
* this actually displays stuff on the screen, it draws a rectangle containing
* the generated/loaded texture.
*/
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texName[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
glEnd();
glutSwapBuffers();
}
void idle(void) {
if (distance < -64) {
distance += delta;
delta -= 0.07;
} else {
if (xpos > 50 || xpos < -50) { xdelta = -xdelta; }
if (ypos > 50 || ypos < -50) { ydelta = -ydelta; }
xpos += xdelta;
ypos += ydelta;
}
renderchecker();
reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
display();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc (keyboard);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
Last edited by dav7 (2008-10-06 19:04:22)
Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.
Offline
Basically, this is the idea. OpenGL is a sane API and worth knowing, if you really want to do anything with imaging. Just read on it (on the redbook, and nowhere else!) from the start and do it right the first time already.
Offline
There are no ponies: if you want realtime graphic transformations, go OpenGL, Clutter, Allegro, SDL and similars. There's also PyGame, that might be good enough for doing simple stuff.
Offline