Jump to content
  • Advertisement
Sign in to follow this  
namingway

Drawing in opengl 2d

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

How can i setup the drawing so that i can assign values in pixels. e.g. 32x32 tiles Because this code just draws a large square in the top left corner.
glTranslatef(-1.0f, 0.0f, 0.0f);
	glColor3f(0.0f, 0.0f, 1.0f);
	glBegin(GL_QUADS);
		glVertex2i(0, 0);
		glVertex2i(1, 0);
		glVertex2i(1, 1);
		glVertex2i(0, 1);
	glEnd();

Share this post


Link to post
Share on other sites
Advertisement
Since you seem to be wanting to do 2D, set an off-center orthographic projection from (0,0) to (width,height).

Share this post


Link to post
Share on other sites
im pretty sure 2d is setup i have glOrtho called and 3d things like depth testing turned off, I just don't know how to draw things like you can in SDL and GDI where you specify pixel coordinates.

Share this post


Link to post
Share on other sites
I don't know SDL, but I guess your question is how to draw your 2d map in opengl. You need to have a nested loop to draw your 2d map. If your tile size is 32 by 32, assign tilewidth and tileheight to 32. The code should be something like this:


for (x = 0 to mapwidth)
{
for (y = 0 to mapheight)
{
glBegin(GL_QUADS);
glVertex2i(x, y);
glVertex2i(x+tilewidth, y);
glVertex2i(x+tilewidth, y+tileheight);
glVertex2i(x, y+tileheight);
glEnd();
}
}

Share this post


Link to post
Share on other sites
no no the map loading code isnt a problem, well it is but its more related to this one...
For now all I want is to draw a 32x32 square onto the screen. How can I do that?

Share this post


Link to post
Share on other sites
I believe you mean to texture map your bitmap tile onto the square you created on the screen. Try to google for some texture mapping tutorials. Check out NeHe tutorial which has a very good sample that shows you how to do texture mapping in opengl. Good luck!

Share this post


Link to post
Share on other sites
As have been said before your solution is to put this at your init when you setup your 2d projection :

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,resX,resY,0,0,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Share this post


Link to post
Share on other sites
this has been solved, i just needed to draw a plain untextured 32x32 square to the screen, which i have now done. However now i am having trouble with the textures as they arent displaying:(

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!