I tested the same shader using SDL and glew and I do not get the odd
lines effect. I guess pyglet is doing something different at some
point but I'm rather clueless right now.
Nicolas
SDL/glew code:
#if 0
#!/bin/sh
FILE=`echo $0 | sed "s/\.cp*$//"`
CC="gcc -g -Wall -pedantic -std=c99"
if [ -z "$SDL_CONFIG" ]; then
SDL_CONFIG="sdl-config"
fi
$CC `$SDL_CONFIG --cflags` $FILE.c -o $FILE `$SDL_CONFIG --libs` -lGL -
lGLU -lGLEW
exit
#endif
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <GL/glew.h>
void printLog(GLuint obj)
{
int infologLength = 0;
char infoLog[1024];
if (glIsShader(obj))
glGetShaderInfoLog(obj, 1024, &infologLength, infoLog);
else
glGetProgramInfoLog(obj, 1024, &infologLength, infoLog);
if (infologLength > 0)
printf("%s\n", infoLog);
}
int main(int argc, char **argv)
{
SDL_Event event;
Uint32 sdlVideoFlags = SDL_OPENGL;
Uint8 quit;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
atexit(SDL_Quit);
int width = 512;
int height = 512;
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (!SDL_SetVideoMode(width, height, 0, sdlVideoFlags)) {
fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glewInit();
if (GLEW_VERSION_2_0) {
fprintf(stderr, "INFO: OpenGL 2.0 supported, proceeding\n");
} else {
fprintf(stderr, "INFO: OpenGL 2.0 not supported. Exit\n");
return EXIT_FAILURE;
}
const char *vsSource[1] = {" \
void main(void) { \
gl_TexCoord[0] = gl_MultiTexCoord0; \
gl_Position = ftransform(); \
}"};
const char *fsSource[1] = {" \
uniform sampler2D image;
\
uniform vec2 pixel;
\
void main()
{ \
vec2 c = gl_TexCoord[0].xy;
\
vec4 tl = texture2D(image, c);
\
vec4 tr = texture2D(image, c+vec2(1,0)*pixel*0.99);
\
vec4 bl = texture2D(image, c+vec2(0,1)*pixel*0.99);
\
vec4 br = texture2D(image, c+vec2(1,1)*pixel*0.99);
\
vec2 f = fract(c/pixel);
\
float a = mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y).a;
\
gl_FragColor = vec4 (a,a,a,1.0);
\
}"};
GLuint vs,fs, sp;
vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, vsSource, NULL);
glCompileShader(vs);
printLog(vs);
fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, fsSource, NULL);
glCompileShader(fs);
printLog(fs);
sp = glCreateProgram();
glAttachShader(sp, vs);
glAttachShader(sp, fs);
glLinkProgram(sp);
printLog(sp);
glUseProgram(sp);
GLint imageLoc = glGetUniformLocation(sp, "image");
GLint pixelLoc = glGetUniformLocation(sp, "pixel");
float data[4*4];
for (int i=0; i<4*4; i++)
data[i] = i/16.0;
GLuint tex_id;
glGenTextures(1, &tex_id);
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, tex_id);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glPixelStorei (GL_PACK_ALIGNMENT, 1);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA16, 4, 4, 0, GL_ALPHA,
GL_FLOAT, data);
glColor4f(1, 1, 1, 1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
quit = 0;
while (!quit) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
quit = 1;
break;
default:
break;
}
}
glClear(GL_COLOR_BUFFER_BIT);
glUniform1f(imageLoc, 0);
glUniform2f(pixelLoc, 1.0/4.0, 1.0/4.0);
glBegin(GL_QUADS);
glTexCoord2f(0,1); glVertex2f(0, 0);
glTexCoord2f(0,0); glVertex2f(0, height);
glTexCoord2f(1,0); glVertex2f(width,height);
glTexCoord2f(1,1); glVertex2f(width,0);
glEnd();
SDL_GL_SwapBuffers();
SDL_Delay(30);
}
glDeleteShader(vs);
glDeleteShader(fs);
glDeleteProgram(sp);
return EXIT_SUCCESS;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---