Jump to content
  • Advertisement

Archived

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

asahetter

Tiling in OpenGL

This topic is 5284 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 all you OpenGL gurus out there. I''m new to this forum so please forgive me for asking a qustion on my very first post. I''ve a good programming background in C/Cpp but I''m pretty new to graphics. I''m working with one of my good hearted proffessors for the summer and he gave me an interesting task that I don''t quite know what I''m doing with. I''ve got a good basis on OpenGL and the glut package but there are some nuances that I just don''t quite get yet. I wrote a texture loader and a simple program to set the tiles. The loader works and I can get a single textured quad to show up in the upper right corner of the window. However I have a bunch of these tiles in a map and this tile that shows is only the lower left tile of a 10 x 10 grid of tiles. All attempts to change the view results in a black screen. I''ve tried both the gluLookAt function and changing the matrix mode to projection sliding the camera and changing the mode back to model view. Anyone out there that can give me a hand? Thank you for any help you can give.

Share this post


Link to post
Share on other sites
Advertisement
The only thing I can personally suggest is make the tile very large (100 by 100), zoom out into the +y and see if that doesn't do anything. It is possible that 99 tiles were drawn beneath the visible one. Are you translating the vertices over or are the vertices set up like this: the first one is (0, 0) - (x, x), the second one is (x, 0) - (2x, x), like that? BTW I assumed your tiles all lie on the X-Z plane.

[edited by - uber_n00b on May 28, 2004 2:00:05 PM]

Share this post


Link to post
Share on other sites
Can you post some code?

quote:

I''m new to this forum so please forgive me for asking a qustion on my very first post.


That''s what this forum is made for!

Share this post


Link to post
Share on other sites
Heres the entireity of the code (comments ripped out). Thanks abunch. rip it apart as you see fit. By the way I stole the map bit from an article on here

#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "textureloader.h"

#define MAP_X 10
#define MAP_Y 10

GLuint texture[2];

char map[MAP_X][MAP_Y] ={
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};

int draw_tiles(GLvoid)
{
int tile, y, x;

for( y = 0; y < MAP_Y; y++)
{
for(x = 0; x {
tile = map[y][x];
glBindTexture(GL_TEXTURE_2D, texture[tile]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(float(x), float(y), 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(float(x +1), float(y), 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(float(x+1), float(y+1), 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(float(x), float(y+1), 0.0);
glEnd();
}
}
}

int load_gl_texture()
{
LoadTexture("tile1.bmp", texture, 0);
LoadTexture("tile2.bmp", texture, 1);
}

void renderScene(void)
{

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);

draw_tiles();

glutPostRedisplay();
glFlush();
glutSwapBuffers();
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 800);
glutCreateWindow("Tiling example");
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);

glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
load_gl_texture();

glClearColor(0.0, 1.0, 0.0, 0.0);
glutMainLoop();
}


[edited by - asahetter on May 28, 2004 2:07:57 PM]

Share this post


Link to post
Share on other sites
I guess there is not anyone that can help me? Darn I''ll try writting the code from the bottom up again and see what happens...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!