Archived

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

ashtray

OpenGL opengl in hardware mode

Recommended Posts

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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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

  • Announcements

  • Forum Statistics

    • Total Topics
      628383
    • Total Posts
      2982372
  • Similar Content

    • By test opty
      Hi all,
       
      I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?
       
       
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Thanks, 
      Dejay Hextrix 
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
  • Popular Now