Advertisement

Grids...

Started by April 01, 2004 04:33 PM
6 comments, last by orcblood 20 years, 11 months ago
Is there a command for rendering an entire grid? Im trying to make a nice simple grid for a background in a program , except I have yet to find a tutorial that could possibly define how to get it right. I dont really want to draw all of the lines in unless I have to, since that would seem to take forever to me. So is there a command for drawing OpenGL grids that I''ve missed?
there is no command for drawing a grid. Simply draw the lines using some sort of loop

Why am I listed as staff?

Oh wait, what was I thinking

[edited by - chowe6685 on April 1, 2004 6:25:21 PM]

[edited by - chowe6685 on April 1, 2004 6:29:05 PM]
Advertisement
quote:
Original post by chowe6685
Why am I listed as staff?



you''ve been promoted. also, think of today''s date. then, if you don''t know check out the lounge forum and read around.

-me

ya its pretty simpile heres what i would do :D
and BTW i have not testing this dont have time right now so if u see a error just point it out and ill fix it.

glBegin(GL_LINES);for(int k=0;k<10;k++){glVertex3f(0.5f*k, 0.0f, 0.0f);glVertex3f(0.5f*k, 5.0f, 0.0f);glVertex3f(0.0f, 0.5f*k, 0.0f);glVertex3f(5.0f, 0.5f*k, 0.0f);}glEnd(); 


hope that helps :D
This is my own function that I came up with to draw a grid ,but you are free to change and utilize it as you please.
void xia_Grid(float VerticleMax, float VerticleMin, float HorizontalMax,              float HorizontalMin, float space, float max, float z){    for(float loop=0.0; loop <= max; loop+=space)    {//Horizontal        glBegin(GL_LINES);            glVertex3f(-HorizontalMin,loop,z);            glVertex3f(HorizontalMax,loop,z);        glEnd();        glBegin(GL_LINES);            glVertex3f(HorizontalMin,-loop,z);            glVertex3f(-HorizontalMax,-loop,z);        glEnd();//Verticle        glBegin(GL_LINES);            glVertex3f(loop,-VerticleMax,z);            glVertex3f(loop,VerticleMin,z);        glEnd();        glBegin(GL_LINES);            glVertex3f(-loop,VerticleMax,z);            glVertex3f(-loop,-VerticleMin,z);        glEnd();    }}
You can use evaluators to draw grids in OpenGL. Look in the OpenGL Resources of this site - an article written by Mark Kilgard (I think that''s how you spell his last name).
People fear what they don''t understand, hate what they can''t conquer!
Advertisement
The code for the grid below draws extremely well, but I cant seem to figure out how to reposition it properly? Im trying to move it more to the left and Ive used several commands (ie gltranslate, but that logically wont work) and different int values but I cant seem to get it right.

glBegin(GL_LINES);    for(int k=0;k<10;k++)    {    glVertex3f(0.5f*k, 0.0f, 0.0f);    glVertex3f(0.5f*k, 5.0f, 0.0f);    glVertex3f(0.0f, 0.5f*k, 0.0f);    glVertex3f(5.0f, 0.5f*k, 0.0f);    }    glEnd(); 
hmm well im not to sure what way left would be but that would be pretty simple heres a EG of how to move make it start at -2 -2 0

Edit: sorry had to remove the code it didnt work ill fix it in a sec

Edit2: ok there here is it :D i made it into a function for you so just put this before the int DrawGLScene(GLvoid) :D or were ever you do all the drawing
Edit3: ok lol last edit i hope :D lol well heres how you use it.
drawgrid(0.0f,0.0f,0.0f,10); just put in the posistion you want to draw it at and the 10 is how many rows.

int drawgrid(float x,float y,float z,int rows){    glTranslatef(x,y,z);    glBegin(GL_LINES);    for(int k=0;k    {       glVertex3f(0.5f*k, 0.0f, 0.0f);       glVertex3f(0.5f*k, 5.0f, 0.0f);           glVertex3f(0.0f, 0.5f*k, 0.0f);       glVertex3f(5.0f, 0.5f*k, 0.0f);    }    glEnd();    glTranslatef(-x,-y,-z);}  


[edited by - kc_0045 on April 2, 2004 6:52:19 PM]

[edited by - kc_0045 on April 2, 2004 7:01:15 PM]

[edited by - kc_0045 on April 2, 2004 7:04:13 PM]

This topic is closed to new replies.

Advertisement