Welcome to Dream.In.Code
Become a VB Expert!

Join 150,140 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,274 people online right now. Registration is fast and FREE... Join Now!




Visual Basic and Open Gl Lag

 
Reply to this topicStart new topic

Visual Basic and Open Gl Lag, Why are only 330 polygons lagging?

geem42
17 Jul, 2008 - 07:29 PM
Post #1

New D.I.C Head
*

Joined: 25 Mar, 2008
Posts: 11

So I've written a program in vb using the OpenGl libraries converted for vb in the "vbofl.tlg" file.

Currently, the program is used to display 330 QUAD-type polygons in glOrtho mode.

12 of the quads are textured
120 of the quads are alpha-blended
198 remaining are solid colors, with blending off

There are approximately 86 lines drawn with GL_LINES

And I used the nehe glPrint routine for text, which uses a List of texture mapped poly's to display a font...
(nehe.gamedev.net)

Everything is drawn in Immediate mode.

...

I have a few questions I'm hoping an expert could resolve:

1) First of all, there are alot of if-thens inside the drawing loops. I figured it's either them, OR draw a bunch of stuff off screen

2) I enable/disable glcBlend, glcTexture2d often to make the most efficient use of the loop. For example:

if i want to blend something with white ill:
switch off glcBlend and texture
start glBegin.
draw the white quad.
glEnd
then re-enable glcBlend
draw the over lapping quad

and loop.

that means glcBlend is constantly going on / off for every iteration, is this bad? It seems that if I want to draw things in layers it would be a lot harder / slower to have two loops one for drawing all under quads, then a second loop later to draw all alpha-blended quads.

3) I often start GL_QUADS and then glEnd for a single quad. Is it faster to bunch a lot of quads all under one "glBegin gl_quads"? Because I know switching textures inside a gl_quads causes a crash, so Im not sure if its proper to enable / disable / change color4f inside a quad block without some unforeseen memory leak.

4) in vb does math lag terrible alot? for example most of the the quads x and y coordinates are calculated by means of at least one or two multiplication operators, division and addition subtraction operators, here is an example of the very worst:

CODE

glVertex3f 100 - OffSet + (LocalNote.Bar - (Int(-GlScrollX / frmView.HScale.Value))) * HScale + (LocalNote.BarPos / 64) * HScale + (LocalNote.Length / 64) * HScale, _
KeyToPixel(LocalNote.Key) + VScale, 0


because all the polys are square the top and bottom left values are the same, as are the top and bottom right values. Also the left and right height values for the top and bottom are the same (because its square...) which means in total id only have to calculate the left side, right side, top side and bottom side once and then store them to temporary variables then use those variables for the quad, but would that really make a difference?


and finally number 5,
5) What are some ways to optimize open gl graphics? I think its ridiculous to lag at 330 (2d-ortho) polys!

This post has been edited by geem42: 17 Jul, 2008 - 07:40 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:12AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month