Newbie Help with open GL and 2D

Started by
0 comments, last by Dzogchener 15 years, 1 month ago
Hi, I am trying to get to grips with open gl, because I want to build something but use 2D essentially. I admit I am not exactly sure how to set things up to work with open gl such that 2D works/looks ok. Right now I want to build a table of quads, as if each quad is a cell of a normal grid/table. Here is some code in Csharp: private void openGLCtrl1_OpenGLDraw(object sender, PaintEventArgs e) { SharpGL.OpenGL gl = this.openGLCtrl1.OpenGL; gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT); gl.LoadIdentity(); gl.Translate(translateX, translateY, translateZ); gl.Begin(OpenGL.QUADS); float cols = 13.0f; float rows = 10.0f; float xplaneSize = 10.0f; float yplaneSize = 10.0f; float widthDim = (float)xplaneSize / cols; float heightDim = (float)yplaneSize / rows; for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { float left = -(xplaneSize / 2) + ((float)c * widthDim); float top = (yplaneSize / 2) - ((float)r * heightDim); gl.Vertex(left, top, 0.0f); gl.Vertex(left + widthDim - 0.05, top, 0.0f); gl.Vertex(left + widthDim-0.05, top - heightDim - 0.05, 0.0f); gl.Vertex(left, top - heightDim - 0.05, 0.0f); } } gl.End(); } So with this code I attempt to draw a table in the middle of the screen. I'd actually like to have the table flush against the borders of the screen, but I am lost as to how to calculate the units/measurements so I can do this (any advice?). So the translateX, translateY members are set to zero, and the transferZ is set to minus 10; When this code runs I get a grid thats not flush with the borders, but worse still is the fact that the table is missing the last column for rows 8, 9 and 10. I think my math above is just not right, and I admit I made them up arbitrarily. I just chose a plane size of 10 for x and y, but I admit I dont know how you work out the measurements. Any advice on how to improve the grid building would be really appreciated. Thanks, D
Advertisement
So I moved the gl.Begin/gl.End into the loop and the grid draws properly. When I change the number of columns x rows I get to a point when the grid stops drawing as a proper table, implying there must be some limit to the number of quads/vertex's you can invoke within gl.Begin/gl.End?

Thanks,

D

This topic is closed to new replies.

Advertisement