Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

something

Drawing in pixels rather than "units"

This topic is 5400 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

Hello, hello! I am trying to make a small tile-based game. At first I used DirectDraw for graphics but I couldn''t figure out how to make things not flicker. Thus, I tried OpenGL. No flicker but I can''t figure out how to draw "sprites" in pixels, rather than as textured quads. I''m pretty sure this is rather easy but since most people are in to 3D nowadays I can''t find anything about it (can''t means don''t have the energy to search for it)

Share this post


Link to post
Share on other sites
Advertisement
In DirectDraw, were you using the back buffer?

Anyway - use the glOrtho to screen setup (look at NeHe''s tutorials), and make sure you''re using the values for the width and height of the client area of the window (where OpenGL is drawing).

That should make it pixel-perfect.

Share this post


Link to post
Share on other sites
Alright, follow up on this one.

I am now trying to draw 32 quads on the x axis. At first I tried a simple for-loop but I noticed that every seventh quad got compressed by one pixel. So, at every seventh quad I have to increase the width of the quad by one pixel.
Also weird is that 16 pixels on the width is one pixel more than on the height.

Now my code for drawing the quads looks like this (x1,y1 are 0 and x2,y2 are 16)
(no, that is not 32 quads but you get the idea):

glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,1.0f);
glVertex2f(x1,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x1,y1);

///////////////////////////////////////////

glTexCoord2f(0.0f,1.0f);
glVertex2f(x2,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2*2+1,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2*2+1,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x2,y1);

///////////////////////////////////////////

glTexCoord2f(0.0f,1.0f);
glVertex2f(x2*2+1,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2*3+1,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2*3+1,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x2*2+1,y1);

//////////////////////////////////////////

glTexCoord2f(0.0f,1.0f);
glVertex2f(x2*3+1,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2*4+1,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2*4+1,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x2*3+1,y1);

//////////////////////////////////////////


glTexCoord2f(0.0f,1.0f);
glVertex2f(x2*4+1,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2*5+1,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2*5+1,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x2*4+1,y1);

////////////////////////////////////////////

glTexCoord2f(0.0f,1.0f);
glVertex2f(x2*5+1,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2*6+1,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2*6+1,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x2*5+1,y1);


////////////////////////////////////////////

glTexCoord2f(0.0f,1.0f);
glVertex2f(x2*6+1,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2*7+2,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2*7+2,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x2*6+1,y1);

////////////////////////////////////////////

glTexCoord2f(0.0f,1.0f);
glVertex2f(x2*7+2,y2+1);

glTexCoord2f(1.0f,1.0f);
glVertex2f(x2*8+2,y2+1);

glTexCoord2f(1.0f,0.0f);
glVertex2f(x2*8+2,y1);

glTexCoord2f(0.0f,0.0f);
glVertex2f(x2*7+2,y1);

glEnd();

Share this post


Link to post
Share on other sites
just a suggestion - make ur viewing height (z) -32 and then draw ur tiles in 1 unit = 1 tiles the advantage being in using units/and 3d is that the player can zoom in and even later u can make the icons and the board 3d and rotate to get and awsome effect

Share this post


Link to post
Share on other sites

  • 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!