Wednesday, 30 November 2011

Code Box Test

Just found this which might help writing blocks of code in my posts...

Let's see;

#include "allegro5/allegro.h"
#include "allegro5/allegro_opengl.h"
#include "allegro5/allegro_image.h"
#include "GL/glu.h"


int main()
{
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_BITMAP *bmp = NULL;

GLuint ogl_tex; // The OpenGL texture id.

al_init();
al_init_image_addon();

al_set_new_display_flags(ALLEGRO_OPENGL);
display = al_create_display(800, 600);

// Load a bitmap to use as a texture
bmp = al_load_bitmap("texture.jpg"); // 256 x 256 pixels
ogl_tex = al_get_opengl_texture(bmp);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(35.0, 800.0 / 600.0, 1.0, 400.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -15.0f);

glEnable(GL_DEPTH_TEST);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ogl_tex);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glBegin(GL_QUADS);

glNormal3f(0.0, 0.0, 1.0);

glTexCoord2f(0.0, 0.0); // Bottom left hand corner
glVertex3f(-1.5, -1.5, 0.0); // X,Y,Z
glTexCoord2f(2.0, 0.0); // Bottom right hand corner
glVertex3f(1.5, -1.5, 0.0); // X,Y,Z
glTexCoord2f(2.0, 2.0); // Top right hand corner
glVertex3f(1.5, 1.5, 0.0); // X,Y,Z
glTexCoord2f(0.0, 2.0); // Top left hand corner
glVertex3f(-1.5, 1.5, 0.0); // X,Y,Z

glEnd();

glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);

al_flip_display();

al_rest(10.0);

glDeleteTextures(1, &ogl_tex);
al_destroy_bitmap(bmp);
al_destroy_display(display);
return 0;
}


How does that look?

Yeah, not too bad. I am learning something about blogging, after all. I'll use that from now on. The font size is 80%.

<"<">

As for the listing in the test example, well, that will be the subject of my next series of posts here.