Re: [Vala] How to bitwise math and implement a jagged array in Vala?
- From: Thomas F Steinhauer <tom_steinhauer hotmail com>
- To: Evan Nemerson <evan coeus-group com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] How to bitwise math and implement a jagged array in Vala?
- Date: Wed, 3 Jul 2013 20:07:25 -0500
Dear Evan,
I tried the code that you have listed, It worked but no texture showed
up on the quads. They were empty.
I have pasted the whole code here as I have it now in hopes that someone
might be able to figure out what is going on or maybe if I did something
wrong.
/*
* Texture: CheckerBoard-pattern texture
*/
const int checkImageWidth = 64; // Texture image rows and columns
const int checkImageHeight = 64;
GLubyte [,,] checkImage; // Texture image data
GLuint texName;
private static uint8[,,] makeCheckImage (int width = 64, int height =
64) {
uint8[,,] check_image = new uint8[height,width,4];
for ( var i = 0 ; i < height ; i++ ) {
for ( var j = 0 ; j < width ; j++ ) {
uint8 c = (((uint8)((i&0x8)==0))^((uint8)((j&0x8)==0)))*255;
check_image[i,j,0] = c;
check_image[i,j,1] = c;
check_image[i,j,2] = c;
check_image[i,j,3] = 255;
}
}
return check_image;
}
void init()
{
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, (GLuint[])texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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, (GLint)GL_RGBA, checkImageWidth,
checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, texName);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(2.41421f, 1.0f, -1.41421f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(2.41421f, -1.0f, -1.41421f);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
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);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.6f);
}
void keyboard (uchar key, int x, int y)
{
switch (key) {
case 27:
//exit(0);
break;
default:
break;
}
}
void main(string[] args)
{
glutInit(ref args.length, args);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow("checker");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
Thanks
Tom
On 07/02/2013 07:02 PM, Evan Nemerson wrote:
On Tue, 2013-07-02 at 18:49 -0500, Thomas F Steinhauer wrote:
I tried your code as you suggested however that did not work. I guess
the real question that I am asking here is has anyone successfully
generated a Checker board type texture with OpenGL and Vala and
displayed it on a cube or square. That is the code that I really need.
It seems that because Vala does not supported "jagged" arrays that this
is not possible or did I miss something in the reading somewhere?
Yes. For one thing, there is no reason this needs to be a jagged array.
The C example isn't. The part of the tutorial I linked to explains the
difference.
Here is everything together. I've changed GL.ubyte to uint8 because it
was more convenient (I don't get an opengl vapi), but s/uint8/GL.ubyte/
and it should be exactly what you're after.
private static uint8[,,]
make_check_image (int width = 64, int height = 64) {
uint8[,,] check_image = new uint8[height,width,4];
for ( var i = 0 ; i < height ; i++ ) {
for ( var j = 0 ; j < width ; j++ ) {
uint8 c = (((uint8)((i&0x8)==0))^((uint8)((j&0x8)==0)))*255;
check_image[i,j,0] = c;
check_image[i,j,1] = c;
check_image[i,j,2] = c;
check_image[i,j,3] = 255;
}
}
return check_image;
}
-Evan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]