PDA

View Full Version : Tiles



-Tony-
04-27-2003, 04:00 AM
Im trying to render tiles with opengl
the window size is 640 * 640

int Board[20][20]

glViewport(0, 0, (GLsizei) 640, (GLsizei) 640);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 640, 0, 0, 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


Im rendering the tiles like this

for(int x = 0; x < 20; ++x)
{
for(int y = 0; y < 20; ++y)
{
glPushMatrix();
glLoadIdentity();
glTranslatef( (float) x * 32.0f, (float) y * 32.0f, 0.0f);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2d(0.0f, 32.0f);

glTexCoord2f(1.0f, 0.0f);
glVertex2d(0.0f, 0.0f);

glTexCoord2f(1.0f, 1.0f);
glVertex2d(32.0f, 0.0f);

glTexCoord2f(0.0f, 1.0f);
glVertex2d(32.0f, 32.0f);

glEnd();
glPopMatrix();
}
}

The problem is that the tiles goes outside of the screen in the upper and upper-right side of the window.

[This message has been edited by -Tony- (edited 04-27-2003).]

-Tony-
04-28-2003, 09:20 AM
anyone?

Finder
04-28-2003, 10:05 AM
Edit:
Sorry, but I was wrong previously. I think you need to set the viewport after glOrtho...not sure, though.

[This message has been edited by Finder (edited 04-28-2003).]

shinpaughp
04-28-2003, 10:33 AM
I tested your code with the following glut app.




#include "stdafx.h"
#include "windows.h"
#include<stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#pragma comment (lib, "glut32.lib")
#pragma comment (lib, "opengl32.lib")
#pragma comment (lib, "glu32.lib")

#include<time.h>

int Board[20][20];

void init()
{
glViewport(0, 0, (GLsizei) 640, (GLsizei) 640);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 640, 0, 0, 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void display()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

for(int x = 0; x < 20; ++x)
{
for(int y = 0; y < 20; ++y)
{
glColor3ub(13 * x, 255 - 13 * y, 6 * (x + y));
glPushMatrix();
glLoadIdentity();
glTranslatef( (float) x * 32.0f, (float) y * 32.0f, 0.0f);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2d(0.0f, 32.0f);

glTexCoord2f(1.0f, 0.0f);
glVertex2d(0.0f, 0.0f);

glTexCoord2f(1.0f, 1.0f);
glVertex2d(32.0f, 0.0f);

glTexCoord2f(0.0f, 1.0f);
glVertex2d(32.0f, 32.0f);

glEnd();
glPopMatrix();
}
}
glFlush();
glutSwapBuffers();
}

void main(int argc, char** argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(640,640);
glutCreateWindow("Picking Object");
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}


Just plugged what you showed into simple glut framework app. No problems. You must be doing something else in your app to cause your problem.

Do the tiles start at the lower left corner, up against the window edge and then go beyond the upper and right sides or is there a gap between the lower and left edges and the start of your tiles? Are you using gluLookAt somewhere in your code, thereby moving the eye from 0.0, 0.0, 0.0? Are you using glScale? Gotta be something else, because the code you showed works properly.

-Tony-
04-28-2003, 10:46 AM
I fixed it by setting the viewport before initializing opengl, the pixelformat stuff.
Im using my own win32 opengl wrapper, maybe it was the problem.
I don't know why though.
Im not using gluLookat, glscale or anything like that.

[This message has been edited by -Tony- (edited 04-28-2003).]

shinpaughp
04-28-2003, 10:52 AM
Calling any gl command before creating and making current a valid context is the same as not calling it at all. Are you sure your window is actually 640 by 640 and not something else? But, the viewport defaults to the size of the window when the context is created so it isn't usually necessary. Anyway, you got it working... all that matters. http://www.opengl.org/discussion_boards/ubb/smile.gif