Archived

This topic is now archived and is closed to further replies.

ashtray

OpenGL opengl in hardware mode

Recommended Posts

ashtray    122
I was wondering how you know if opengl is running in hardware mode or software mode. I made a surface with GL_QUADS that was 1 * 1 big, the did 2 for loops to draw that surface to be 200 * 200 (while using glTranslate...) and added a texture to it and if I don''t use the textures, I get about 60 fps and if I add the texture which is 96 pixels by 96 pixels, I get fps ranging from 21 to 18. I was just wondering if I might be running in software mode instead of hardware mode and this would be why my little program is sooo slow. thx for any help in advance.. ashtray.. ...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Make sure you don''t load the texture each frame, instead of loading it once at the beginning of your program. This would explain the huge fps decrease.

Share this post


Link to post
Share on other sites
MazyNoc    122
quote:
Original post by ashtray
if I add the texture which is 96 pixels by 96 pixels, I get fps ranging from 21 to 18.


...



If your not using any new extension your texture must have dimensions of 2^x at each side..

2^x will never be 96 if x is an integer.. make it 64*64 or 128*128

Share this post


Link to post
Share on other sites
Trienco    2555
and of course dont bind it for every single quad. also if you use immediate mode and a lot of glvertex calls then doing translate AND glvertex means twice more work then necessary.

and yes, using "odd" texture sizes might be possible by now, but its still slow.

Share this post


Link to post
Share on other sites
OrangyTang    1298
quote:
Original post by ashtray
I was wondering how you know if opengl is running in hardware mode or software mode.


In windows, glGet with GL_VENDOR and GL_RENDERER. If you see something like ''Generic microsoft'' you''re getting the software fallback. Typically you''ll see the name of the manufacturer of your video card.

But you could still be getting a non-accelerated display, most commonly if you request a funny/non-standard framebuffer format (nVidia cards tend to baulk at having high/mismatched depth and stencil bits on a 16bit desktop for example).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Hello,

I changed my texture to be of size 128 * 128

I what I meant by 96 * 96 was dots per inch (the resolution), does this need to be changed as well? or does my 128 pixels * 128 pixels new size good now keeping the same resolution?


I am also binding once, before my loops,

I think I''m doing something wrong because it''s still very slow...

Here''s my code...

in my render function I have this building my "ground or floor"

void render()
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int i, j;

glEnable(GL_TEXTURE_2D);

glBindTexture( GL_TEXTURE_2D, grassTexture );
for (i = 0; i <= 200; i++ ) {
for (j = 0; j <= 200; j++ ) { // largeur 3.1m
glPushMatrix();
glTranslatef( i, 0.0f, j );
glCallList(floor_display_list);
glPopMatrix();
}
}

glDisable(GL_TEXTURE_2D);

glFlush(); // Flush drawing commands
glutSwapBuffers();

}

and the display list function for creating my "floor" is

void drawFloor() {

glBegin(GL_QUADS);
glVertex3f( 0.0f, 0.0f, 0.0f);
glTexCoord2f( 0.0f, 0.0f);
glVertex3f( 1.0f, 0.0f, 0.0f);
glTexCoord2f( 1.0f, 0.0f);
glVertex3f( 1.0f, 0.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f);
glEnd();
}

Share this post


Link to post
Share on other sites
ashtray    122
This is the version info (and more) that I am using.

From what I understand, I am in hardware mode... right?

GL_VENDOR -> NVIDIA Corporation
GL_RENDERER -> GeForce4 MX 420 with AGP8X/AGP/3DNOW!
GL_VERSION -> 1.3.1
GL_EXTENSIONS -> GL_ARB_imaging GL_ARB_multitexture GL_ARB_texture_compression GL_ARB_texture_cube_map GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_dot3 GL_ARB_transpose_matrix GL_S3_s3tc GL_EXT_abgr GL_EXT_bgra GL_EXT_blend_color GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_clip_volume_hint GL_EXT_compiled_vertex_array GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_multi_draw_arrays GL_EXT_packed_pixels GL_EXT_paletted_texture GL_EXT_point_parameters GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_shared_texture_palette GL_EXT_stencil_wrap GL_EXT_texture_compression_s3tc GL_EXT_texture_edge_clamp GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 GL_EXT_texture_cube_map GL_EXT_texture_filter_anisotropic GL_EXT_texture_lod GL_EXT_texture_lod_bias GL_EXT_texture_object GL_EXT_vertex_array GL_EXT_vertex_weighting GL_IBM_texture_mirrored_repeat GL_KTX_buffer_region GL_NV_blend_square GL_NV_evaluators GL_NV_fence GL_NV_fog_distance GL_NV_light_max_exponent GL_NV_packed_depth_stencil GL_NV_register_combiners GL_NV_texgen_emboss GL_NV_texgen_reflection GL_NV_texture_env_combine4 GL_NV_texture_rectangle GL_NV_vertex_array_range GL_NV_vertex_array_range2 GL_NV_vertex_program GL_NV_vertex_program1_1 GL_SGIS_generate_mipmap GL_SGIS_multitexture GL_SGIS_texture

Share this post


Link to post
Share on other sites
Yann L    1802
quote:

glBindTexture( GL_TEXTURE_2D, grassTexture );
for (i = 0; i <= 200; i++ ) {
for (j = 0; j <= 200; j++ ) { // largeur 3.1m
glPushMatrix();
glTranslatef( i, 0.0f, j );
glCallList(floor_display_list);
glPopMatrix();
}
}


There are two major performance sinks in this code, and a multitude of smaller ones.

The to big problems are the matrix stuff, and the display list call. You are basically performing more than 40000 matrix multiplication and display list calls per frame ! No wonder, that this is slow. Try this instead:


glBindTexture( GL_TEXTURE_2D, grassTexture );
glBegin(GL_QUADS);
for (i = 0; i <= 200; i++ ) {
for (j = 0; j <= 200; j++ ) { // largeur 3.1m

glTexCoord2f( 0.0f, 0.0f);
glVertex3f( i, 0.0f, j);
glTexCoord2f( 1.0f, 0.0f);
glVertex3f( i+1, 0.0f, j);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( i+1, 0.0f, j+1);
glTexCoord2f(0.0f, 1.0f);
glVertex3f( i, 0.0f, j+1);
}
}
glEnd();


Oh, and there was a bug with the texture coordinates, btw: you have to set the vertex attributes (such as texcoords) before sending the vertex position (which will dispatch the vertex to the GPU).

This code above can of course still be tremendeously optimized: using triangle strips, for example. You''ll get the greatest performance boost by dropping immediate mode altogether, and using vertex arrays (or variants).

Share this post


Link to post
Share on other sites
ashtray    122
OK, thx for the tips.

I thought that using display list would increase my performance because the shape that I am drawing is already compiled. When should one use display lists? I though you did when you were repeating a patterns of something drawn.

Also, if I do use triangle strips, how would I go about adding a square texture onto the triangles. if I draw 2 triangles to make one square, how would I attach my texture to my new square.

I''ve looked for good tutorials on texturing but did not find anything that really suited my needs. How to attach it properly to the object, etc...

I also do not understand what you mean by "dropping immediate mode altogether, and using vertex arrays"

As you probably guessed, I''m new to opengl... what is "immediate mode"

I really appreciate you taking the time to answer my questions.

thx.


Share this post


Link to post
Share on other sites
ashtray    122
about immediate mode,
I knew what it was but forgot it was called immediate mode...
(command is executed as soon as the server receives it) but doesn''t having a display list give it all in one shot? so the transformations and drawing that I''m doing count at one command and not 4 because they are pre-compiled?

I changed my code yo use yours (trashed the display list and fixed the tex coord (thx)) and I only gained 5 fps. I''m looking into triangle stips now.

Share this post


Link to post
Share on other sites
ashtray    122
you were right about the triangle strips... They are much faster the the quads I was using.


I''m still confused about the display lists. What if I wanted to build cubes and pyramids on top (to make it look like a ''cheap'' house, would it be better to use display lists for that?





Share this post


Link to post
Share on other sites
OrangyTang    1298
quote:
Original post by ashtray
I''m still confused about the display lists. What if I wanted to build cubes and pyramids on top (to make it look like a ''cheap'' house, would it be better to use display lists for that?


Display lists are only faster when they contain a large amount of polys. I forget the exact number but they start being efficient at about ~400 tris. For small scale stuff like this its probably easier to use immediate mode, or try building one vertex array for the whole floor and then telling GL to render it all at once. Or better yet, build one vertex array at the start and only rebuild it when anything changes.

Share this post


Link to post
Share on other sites
ashtray    122
I think I understand now. Is there a doc for optimization techniques comewhere?

SO what I can do is write a function that draws my initial landscape and only update it when something changes like movement ("walking" through my landscape) or any other graphic change or whatever.

Would I use the idleFunc for this? I never in any docs where or how to use that functions.

will this make navigation choppy?

I really appreciate your replies.

I had one more question... If I only use basically 2 big tris to make my whole 200 * 200, How would I attach my texture tiled if my texture is for example 1 * 1 (well, really 128 pixels * 128 pixels )? How would I be able to make it look like it''s been attached to 1*1 squares made of 2 tris and not attached just once on the 200 * 200 square?

If I should be in an other newsgroup... I can always post there..

thx.

Share this post


Link to post
Share on other sites
Roland    138
You could use diffrent u and v coordinates.
When you use for instance 5.0 instead of 1.0 as u and v coordinate the texture would be repeated 5 times.
But you must set the texture wrap mode correctly. Should be something like:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);

[edited by - Roland on August 10, 2003 5:34:23 AM]

Share this post


Link to post
Share on other sites
Basiror    241
quote:
Original post by Trienco
and of course dont bind it for every single quad. also if you use immediate mode and a lot of glvertex calls then doing translate AND glvertex means twice more work then necessary.

and yes, using "odd" texture sizes might be possible by now, but its still slow.




if you use glu build mipmaps functions you can uses texture not multiple of 2



Share this post


Link to post
Share on other sites
GamerSg    378
U can still optimise the code further by using display lists.

You can compile your code into a display list at load time.
glNewList(GL_COMPILE,LISTNUMBER);
glBindTexture( GL_TEXTURE_2D, grassTexture );
glBegin(GL_QUADS);
for (i = 0; i <= 200; i++ ) {
for (j = 0; j <= 200; j++ ) { // largeur 3.1m
glTexCoord2f( 0.0f, 0.0f);
glVertex3f( i, 0.0f, j);
glTexCoord2f( 1.0f, 0.0f);
glVertex3f( i+1, 0.0f, j);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( i+1, 0.0f, j+1);
glTexCoord2f(0.0f, 1.0f);
glVertex3f( i, 0.0f, j+1); }}
glEnd();
glEndList();

Then when u need to call it just use glCallList(LISTNUMBER).

You should see a huge performance gain because you are now making 1 call instead of 40 000.

[edited by - GamerSg on August 10, 2003 11:49:21 AM]

Share this post


Link to post
Share on other sites
Trienco    2555
quote:
Original post by Basiror
if you use glu build mipmaps functions you can uses texture not multiple of 2


nobody said you cant.. but just because its possible doesnt mean you should do it. though if i were a 3d api id probably just take that odd texture and blow it up to the next power of 2 size *fg*

Share this post


Link to post
Share on other sites
Rasmadrak    196
Hi there!

I''m making an RTS and I''m having the same problem...
major slowdowns as the polycount increases...
around 3-400 polys = unplayable...

So to optimize:

Minimize glPopMatrix,glPushMatrix calls...?

Build the entire map in a displaylist -( wouldn''t that be acctually slower than rendering each tile, only rendering the visible ones?)

Should I use glTranslate instead of pop/pushmatrix?

Minimize glBindTexture() .... How would I then change textures?
Do you mean, sort all units of the same type and then draw them in a loop...?

Right now I''m doing it this way:

for (int i = 1; i < NrOfUnits+1;i++)
{
glBindTexture(Unit.Texture);
glPushMatrix()
glTranslate(Unit[i].x,Unit[i].y,Unit[i].z);
glCallList(Unit[i].Model);
glPopMatrix();
}

Would it be better to sort all the units and then draw them in "order"?





"Game Maker For Life, probably never professional thou." =)

Share this post


Link to post
Share on other sites

  • Partner Spotlight

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now