Advertisement Jump to content
Sign in to follow this  
thepillowz

AllegroGL 2D Troubles

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

If you intended to correct an error in the post then please contact us.

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);
glLoadIdentity();
glOrtho(0,0,640,480,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLuint sprLinkTex;
int TexWidth;
int TexHeight;
GLubyte *TexDat;
BITMAP *sprLink = load_bitmap("sprLinkDS.bmp",NULL);
sprLinkTex = allegro_gl_make_texture_ex(AGL_TEXTURE_MASKED,sprLink,GL_RGBA);
glBindTexture(GL_TEXTURE_2D,sprLinkTex)
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);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
  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();
readkey();
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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!