Results 1 to 6 of 6

Thread: Tiles

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    7

    Tiles

    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).]

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    7

    Re: Tiles

    anyone?

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2003
    Posts
    14

    Re: Tiles

    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).]

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: Tiles

    I tested your code with the following glut app.

    Code :
    #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.

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    7

    Re: Tiles

    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).]

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: Tiles

    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.

Similar Threads

  1. gaps between 2D tiles
    By codetale in forum OpenGL: Basic Coding
    Replies: 16
    Last Post: 11-16-2010, 11:22 PM
  2. Tiles better algorithms
    By juglarx in forum OpenGL: General
    Replies: 2
    Last Post: 07-16-2007, 12:53 AM
  3. weird see-thru tiles
    By Xero_Tolerance in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-27-2002, 09:15 PM
  4. tiles quality
    By MarsuGL in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 07-18-2001, 01:30 PM
  5. TILES
    By iNeedNewsox in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 04-13-2001, 05:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean