# AllegroGL 2D Troubles

This topic is 4519 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having problems with my code to display 2D. I'm using AllegroGL but this pertains mostly to OpenGL. Heres the code:
#include <allegro.h>
#include <alleggl.h>
int main()
{
allegro_init();
install_allegro_gl();
install_keyboard();
allegro_gl_set(AGL_Z_DEPTH, 8);
allegro_gl_set(AGL_COLOR_DEPTH, 16);
allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH);
allegro_gl_set(AGL_REQUIRE, AGL_DOUBLEBUFFER);
set_gfx_mode(GFX_OPENGL_WINDOWED,640,480,0,0);
glMatrixMode(GL_PROJECTION);
glOrtho(0,0,640,480,-1,1);
glMatrixMode(GL_MODELVIEW);
int TexWidth;
int TexHeight;
GLubyte *TexDat;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TexWidth,TexHeight,0,GL_RGBA,
GL_UNSIGNED_BYTE,TexDat);
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glColor4ub(255, 255, 255, 255);
glTexCoord2d(0, 0); glVertex2d(-0.5,0.5);
glTexCoord2d(6, 0); glVertex2d(0.5,0.5);
glTexCoord2d(6, 6); glVertex2d(0.5,-0.5);
glTexCoord2d(0, 6); glVertex2d(-0.5,-0.5);
glEnd();
allegro_gl_flip();
return 0;
}
END_OF_MAIN();
It loads the sprite and places it onto the Quad but it is scaled and blended. Thats the problem I want to fix that problem so that it will display the sprites correct size and just be unchanged. Also the gltexcoord and glvertex have some messed up values but I was just testing those. I'm new to OpenGL so any suggestions to get rid of some functions or add-in things would be helpful too. Thanks for any help.

##### Share on other sites
Quote:
 Original post by thepillowz glTexCoord2d(0, 0); glVertex2d(-0.5,0.5); glTexCoord2d(6, 0); glVertex2d(0.5,0.5); glTexCoord2d(6, 6); glVertex2d(0.5,-0.5); glTexCoord2d(0, 6); glVertex2d(-0.5,-0.5);

Try switching those arguments.

##### Share on other sites
Do you mean change the values or actually switch them as in:
glVertex2d(-0.5,0.5);glTexCoord2d(0, 0);
I tried both things but when I change values it is still scaled but I stopped it from blending. Any other ideas?

##### Share on other sites
If your image is 6 pixels by 6 pixels, maybe this would work.

Quote:
 glVertex2f(0.0f,0.0f); glTexCoord2f(-0.5f, 0.5f); glVertex2f(6.0f,0.0f); glTexCoord2f( 0.5f, 0.5f); glVertex2f(6.0f,6.0f); glTexCoord2f( 0.5f,-0.5f); glVertex2f(0.0f,6.0f); glTexCoord2f(-0.5f,-0.5f);

##### Share on other sites

This topic is 4519 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.