FAQ: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
(Undo revision 2591 by Alfonse (Talk)Mistake. Sorry.)
(Multiple changes, removal of <br>s.)
Line 4: Line 4:


=== What is OpenGL? ===
=== What is OpenGL? ===
OpenGL stands for Open Graphics Library. It is an API for doing 3D graphics.<br>
OpenGL stands for Open Graphics Library. It is an API for doing 3D graphics.
In more specific terms, it is an API that is used to "draw triangles on your scene". In this age of GPUs, it is about talking to the GPU
 
so that it does the job of drawing. It does not deal with file formats. It does not open bmp, png and any image format. It does not
In more specific terms, it is an API that is used to "draw triangles on your scene". In this age of GPUs, it is about talking to the GPU so that it does the job of drawing. It does not deal with file formats. It does not open bmp, png and any image format. It does not open 3d object formats like obj, max, maya. It does not do animation. It does not handle keyboard, mouse and any input devices. It does not create a window, and so on.
open 3d object formats like obj, max, maya. It does not do animation. It does not handle keyboard, mouse and any input devices. It does not
 
create a window, and so on.<br>
All that stuff should be handled by an external library (GLUT is one example that is used for creating and destroying a window and handling mouse and keyboard).
All that stuff should be handled by an external library (GLUT is one example that is used for creating and destroying a window and handling mouse and keyboard).<br>
 
GL has gone through several versions : 1.0, 1.1, 1.2, 1.2.1, 1.3, 1.4, 1.5, 2.0, 2.1, 3.0<br>
GL has gone through a number of versions.
At each versions, extensions of interest are introduced into the core. Usually, they are all <b>ARB</b> extensions.<br>


=== Who maintains? ===
=== Who maintains? ===
GL is created at SGI. Later on, the Architectural Review Board (ARB) controlled it which is a collection of major graphics companies.<br>
 
Control was transfered to Khronos, which is another collection of major graphics companies. Their website is at http://www.khronos.org
The [[OpenGL Architectural Review Board]] or ARB.
and they are specially known for OpenGL ES in which the ES means Embeded System (cellphones, PDA, consoles such as the Playstation 3 (PS3)) and other Open Spec
APIs. You can find the list of companies at Khronos' website.


=== Open Source? ===
=== Open Source? ===
No, OpenGL doesn't have any source code. GL is a specification which can be found on this website. It describes the interface the programmer uses and
No, OpenGL doesn't have any source code. GL is a specification which can be found on this website. It describes the interface the programmer uses and expected behavior. OpenGL is an open ''specification''. Anyone can download the spec for free. This is as opposed to ISO standards and specifications, which cost money to access.
expected behavior. OpenGL is Open Spec. Anyone can download the spec for free.<br>
 
There is an implementation of GL that is Open Source and it is called Mesa3D http://www.mesa3d.org<br>
There is an implementation of GL that is Open Source and it is called Mesa3D http://www.mesa3d.org
 
It doesn't have the license to call itself OpenGL, but it does follow the spec very well.
It doesn't have the license to call itself OpenGL, but it does follow the spec very well.


=== Where can I download? ===
=== Where can I download? ===
Just like the "Open Source?" section explains, GL is not a software product. GL is a specification.<br>
Just like the "Open Source?" section explains, GL is not a software product. GL is a specification.
Companies like nVidia and AMD/ATI use the spec to write their drivers, so OpenGL is in fact included in the drivers that they supply.<br>
 
Companies like nVidia and AMD/ATI use the spec to write their drivers, so OpenGL is in fact included in the drivers that they supply.
 
For laptop owners, you need to visit the manufacturer of your laptop and download the drivers from them.
For laptop owners, you need to visit the manufacturer of your laptop and download the drivers from them.


=== Where can I download? #2 ===
=== Where can I download? #2 ===
When you update your video driver, this is good enough for people who want to play games or run some application.<br>
When you update your video driver, this is good enough for people who want to play games or run some application.
For programmers, installing drivers will not give you a gl.h file. It will not give you opengl32.lib. Those are files that come with your compiler (on Windows, your compiler might need opengl32.lib or perhaps opengl32.a).<br>
For programmers, installing drivers will not give you a gl.h file. It will not give you opengl32.lib. Those are files that come with your compiler (on Windows, your compiler might need opengl32.lib or perhaps opengl32.a).
Also, there are no updated gl.h and opengl32.lib file. These are stuck at GL 1.1 and will be forever. Read the Getting Started section to learn what you must do. http://www.opengl.org/wiki/Getting_started<br>
Also, there are no updated gl.h and opengl32.lib file. These are stuck at GL 1.1 and will be forever. Read the Getting Started section to learn what you must do. http://www.opengl.org/wiki/Getting_started
Also, installing a video driver will not replace opengl32.dll. It is a system file and belongs to Windows. Only Microsoft may update it.<br>
Also, installing a video driver will not replace opengl32.dll. It is a system file and belongs to Windows. Only Microsoft may update it.
When you install a video driver, another file will be copied to your system (nvoglv32.dll in the case of nVidia) and the registry will be modified.<br>
When you install a video driver, another file will be copied to your system (nvoglv32.dll in the case of nVidia) and the registry will be modified.
opengl32.dll will call into the real GL driver (nvoglv32.dll).
opengl32.dll will call into the real GL driver (nvoglv32.dll).


=== SDK ===
=== SDK ===
See this page<br>
There is no actual OpenGL SDK. There is a collection of websites, some (outdated) documentation, and links to tutorials, all found [http://www.opengl.org/wiki/Getting_started#SDK here]. But it is not an SDK of the kind you are thinking about.
http://www.opengl.org/wiki/Getting_started#SDK
 
<br>
NVIDIA and ATI have their own SDKs, both of which have various example code for OpenGL.
There isn't an official SDK from http://www.opengl.org however 3rd party individuals have made great websites and tutorials, companies like nVidia and ATI/AMD have made available many small projects that demonstrate GL features.<br>
If you are new and want to understand what you must do, the 2 most important pages on this Wiki are : this FAQ page and also http://www.opengl.org/wiki/Getting_started


=== What platforms have GL? ===
=== What platforms have GL? ===
Windows : 95 and above<br>
* Windows: 95 and above
Mac OSX : all versions<br>
* Mac OSX: all versions
Linux : this depends on the distributions. Distros meant for desktop usage come with Gnome, KDE or some windows manager and OpenGL
* Linux: this depends on the distributions. Distros meant for desktop usage come with Gnome, KDE or some windows manager and OpenGL is either supplied as Mesa (software rasterizer) or they provide proper drivers.
is either supplied as Mesa (software rasterizer) or they provide proper drivers.<br>
* FreeBSD: unknown
FreeBSD : unknown<br>
Cellphones, PDA, consoles such as the Playstation 3 (PS3) have OpenGL ES.<br>
OpenGL ES  is a subset of OpenGL. For example, it has VBO suppport but glBegin and glEnd have been removed.<br>
Despite the fact that PS3 offers GL ES and Cg, most games don't use it. Instead, the companies use the more low level libraries available on that platform.


=== Which 3D API is better? ===
OpenGL ES is often supported on embedded systems, but OpenGL ES is a different API from regular OpenGL.
This question is asked by newcomers. They want to know whether they should chose OpenGL or DirectX.<br>
It should be noted that GL can't be compared to DX since DX has additional features like DirectSound, DirectPlay, DirectInput, DirectMusic, DirectDraw, the DirectX Utility.<br>
GL should be compared only to Direct3D.<br>
If you need sound support, you can use FMod, Bass, OpenAL and others.<br>
For a math library, there are many. For image loaders, there are many as well.<br>
For a complete list, visit the Alternative Game Libraries forum at http://www.gamedev.net/community/forums<br>
<br>
For D3D vs GL, there are many discussions on forums. This is one such example<br>
http://www.gamedev.net/community/forums/topic.asp?topic_id=510845
<br>
<br>
In general, the more you know, the better, so it is recommended that you start with one or the other. Learning the other later on will be easy.<br>


=== How Does It Work On Windows? ===
=== How Does It Work On Windows? ===
All Windows versions support OpenGL.<br>
All Windows versions support OpenGL.
When you compile an application, you link with opengl32.dll (even on Win64).<br>
 
When you run your program, opengl32.dll gets loaded and it checks in the Windows registry if there is a true GL driver. If there is, it will load it. For example, ATI's GL driver name starts with atioglxx.dll and nVidia's GL driver is nvoglv32.dll. The actual names change from release versions.<br>
When you compile an application, you link with opengl32.dll (even on Win64).
opengl32.dll is limited to 1.1. When you make a call like glBindTexture, it jumps to opengl32.dll and it checks if there is a driver. If there is, it calls the true driver bind function. There are many GL 1.1 functions such as glLoadMatrixf, glPushMatrix, glOrtho, glEnable, glTexEnvi.<br>
 
<br>
When you run your program, opengl32.dll gets loaded and it checks in the Windows registry if there is a true GL driver. If there is, it will load it. For example, ATI's GL driver name starts with atioglxx.dll and nVidia's GL driver is nvoglv32.dll. The actual names change from release versions.
For GL >=1.2 functions, you get a function pointer with wglGetProcAddress. Examples are glActiveTexture, glBindBuffer, glVertexAttribPointer. wglGetProcAddress returns an address from the real driver in these cases.<br>
 
<br>
opengl32.dll is limited to 1.1. For GL >=1.2 functions, you get a function pointer with wglGetProcAddress. Examples are glActiveTexture, glBindBuffer, glVertexAttribPointer. wglGetProcAddress returns an address from the real driver in these cases.
The above is just to inform you how it works under the hood. It has no impact on you as a programmer. It has no performance impact.<br>
 
To compare with Direct3D, in direct3D, you get a COM object to something called the device. This COM object has a table of pointers for every function so that you can call d3ddevice->SetRenderState(). Again, there is no performance impact. GL and D3D don't have an advantage one over the other.<br>
The only important thing to know is that opengl32.dll belongs to Microsoft. No one can modify it. You '''must not''' replace it. You '''must not''' ship your application with this file. You must not ship nvoglv32.dll or any other system file either.
The only important thing to know is that opengl32.dll belongs to Microsoft. No one can modify it. You <b>must not</b> replace it. You <b>must not</b> ship your application with this file. You must not ship nvoglv32.dll or any other system file either.<br>
 
It is the responsibility of the user to install the driver made available from Dell, HP, nVidia, ATI/AMD, Intel, SiS, and whatever.
It is the responsibility of the user to install the driver made available from Dell, HP, nVidia, ATI/AMD, Intel, SiS, and whatever. Though feel free to remind them to do so.
 
=== How do I tell what version of OpenGL I'm using? ===
Use the function <code>glGetString(GL_VERSION)</code>. This will return a null-terminated string. Do not copy this string into a fixed-length buffer, as it can be fairly long.
 
The string has a specific format:
 
  <nowiki><major version>.<minor version></nowiki>
 
Following the minor version can be another '.' with a vendor-specific build number. Following that is entirely vendor-specific information. The format of this information is up to the driver writers.
 
Alternatively, you can use <code>glGetIntegerv(GL_MAJOR_VERSION, *)</code> and <code>glGetIntegerv(GL_MAJOR_VERSION, *)</code>. These require GL 3.0 or greater, however.


=== Why is my GL version only 1.4 or lower? ===
=== Why is my GL version only 1.4 or lower? ===


There are two reasons you may get a low OpenGL version.
There are two reasons you may get an unexpectedly low OpenGL version.


On Windows, you may be a low GL version if, during [[Creating an OpenGL Context|context creation]], you use an unaccelerated pixel format. This means you get the default implementation of OpenGL. Depending on whether you are using Windows Vista or earlier versions of Windows, this may mean you get a software GL 1.1 implementation, or a hardware GL 1.5 implementation.
On Windows, you may be a low GL version if, during [[Creating an OpenGL Context|context creation]], you use an unaccelerated pixel format. This means you get the default implementation of OpenGL. Depending on whether you are using Windows Vista or earlier versions of Windows, this may mean you get a software GL 1.1 implementation, or a hardware GL 1.5 implementation.
Line 109: Line 102:


=== How to render in pixel space ===
=== How to render in pixel space ===
There are 2 ways to do it
Setup a certain projection matrix
1. Setup a certain projection matrix
   glMatrixMode(GL_PROJECTION);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glLoadIdentity();
Line 118: Line 110:
   glLoadIdentity();
   glLoadIdentity();


Notice that y axis goes from bottom to top because of the glOrtho call. You can swap bottom and top parameters if you want y to go from top to bottom. make sure you render your polygons in the right order so that GL doesn't cull them or just call glDisable(GL_CULL_FACE).<br>
Notice that y axis goes from bottom to top because of the glOrtho call. You can swap bottom and top parameters if you want y to go from top to bottom. make sure you render your polygons in the right order so that GL doesn't cull them or just call glDisable(GL_CULL_FACE).
<br>
2. The second method is to use glWindowPos which ignores the projection and modelview matrices.<br>
You can use glWindowPos2f or glWindowPos3f so perhaps the z component doesn't matter for you and you can set it to 0.0.<br>
You can try glWindowPos2i, glWindowPos3i, glWindowPos2d, glWindowPos3d, glWindowPos2s, glWindowPos3s but that depends on what format the GPU supports. http://www.opengl.org/wiki/Common_Mistakes#Unsupported_formats_.231<br>
glWindowPos basically changes the raster position. Then you would need to call glBitmap or glDrawPixels to render. Keep in mind that glBitmap or glDrawPixels are not recommended for rendering. It's always best to render polygons since that's what GPUs prefer.


=== Multi indexed rendering ===
=== Multi indexed rendering ===
Line 131: Line 118:
It is up to you the user to adjust your data format so that there is only one index array, which samples from multiple attribute arrays. To do this, you will need to duplicate some attribute data so that all of the attribute lists are the same size.
It is up to you the user to adjust your data format so that there is only one index array, which samples from multiple attribute arrays. To do this, you will need to duplicate some attribute data so that all of the attribute lists are the same size.


 
Quite often, this question is asked by those wanting to use the OBJ file format:
Quite often, people asking this question are people who want to use the OBJ file format:


   v 1.52284 39.3701 1.01523
   v 1.52284 39.3701 1.01523
Line 161: Line 147:
* [[Vertex Specification]]
* [[Vertex Specification]]


=== glGetString(GL_VERSION) ===
=== glClear and glScissor ===
This returns a string which may look something like "2.0.6914 WinXP SSE/SSE2/SSE3/3DNow!"<br>
glScissor is one of the few functions that effect on how glClear operates. If you want to clear only a region of the back buffer, then call glScissor and also glEnable(GL_SCISSOR_TEST).
2.0 is the actual version number of GL supported. All the rest depends on what information the IHV wants to convey and is not part of the GL standard. 6914 would be the driver version. WinXP is the OS. SSE/SSE2/SSE3/3DNow! are CPU features that the driver can use in case it runs in software mode.<br>
In glhlib http://www.geocities.com/vmelkon/glhlibrary.html<br>
glhGetIntegerv(GLH_OPENGL_VERSION, version) can return the major and minor version. That is to say, version[0] would be an integer (2) and version[1] is an integer (0). This is a utility library similar to GLU to make programming easier.<br>
Also note that at times glGetString(GL_VERSION) returns also the bus type used such as AGP or PCI or PCIEx.


=== glClear and glScissor ===
glScissor is one of the few functions that effect on how glClear operates. If you want to clear only a region of the back buffer, then call glScissor and also glEnable(GL_SCISSOR_TEST).<br>
Alternatively, if you have used the scissor test and forgot to glDisable(GL_SCISSOR_TEST), then you might wonder why glClear isn't working the way you want to.
Alternatively, if you have used the scissor test and forgot to glDisable(GL_SCISSOR_TEST), then you might wonder why glClear isn't working the way you want to.



Revision as of 19:02, 16 September 2009

Welcome to the FAQ

What is OpenGL?

OpenGL stands for Open Graphics Library. It is an API for doing 3D graphics.

In more specific terms, it is an API that is used to "draw triangles on your scene". In this age of GPUs, it is about talking to the GPU so that it does the job of drawing. It does not deal with file formats. It does not open bmp, png and any image format. It does not open 3d object formats like obj, max, maya. It does not do animation. It does not handle keyboard, mouse and any input devices. It does not create a window, and so on.

All that stuff should be handled by an external library (GLUT is one example that is used for creating and destroying a window and handling mouse and keyboard).

GL has gone through a number of versions.

Who maintains?

The OpenGL Architectural Review Board or ARB.

Open Source?

No, OpenGL doesn't have any source code. GL is a specification which can be found on this website. It describes the interface the programmer uses and expected behavior. OpenGL is an open specification. Anyone can download the spec for free. This is as opposed to ISO standards and specifications, which cost money to access.

There is an implementation of GL that is Open Source and it is called Mesa3D http://www.mesa3d.org

It doesn't have the license to call itself OpenGL, but it does follow the spec very well.

Where can I download?

Just like the "Open Source?" section explains, GL is not a software product. GL is a specification.

Companies like nVidia and AMD/ATI use the spec to write their drivers, so OpenGL is in fact included in the drivers that they supply.

For laptop owners, you need to visit the manufacturer of your laptop and download the drivers from them.

Where can I download? #2

When you update your video driver, this is good enough for people who want to play games or run some application. For programmers, installing drivers will not give you a gl.h file. It will not give you opengl32.lib. Those are files that come with your compiler (on Windows, your compiler might need opengl32.lib or perhaps opengl32.a). Also, there are no updated gl.h and opengl32.lib file. These are stuck at GL 1.1 and will be forever. Read the Getting Started section to learn what you must do. http://www.opengl.org/wiki/Getting_started Also, installing a video driver will not replace opengl32.dll. It is a system file and belongs to Windows. Only Microsoft may update it. When you install a video driver, another file will be copied to your system (nvoglv32.dll in the case of nVidia) and the registry will be modified. opengl32.dll will call into the real GL driver (nvoglv32.dll).

SDK

There is no actual OpenGL SDK. There is a collection of websites, some (outdated) documentation, and links to tutorials, all found here. But it is not an SDK of the kind you are thinking about.

NVIDIA and ATI have their own SDKs, both of which have various example code for OpenGL.

What platforms have GL?

  • Windows: 95 and above
  • Mac OSX: all versions
  • Linux: this depends on the distributions. Distros meant for desktop usage come with Gnome, KDE or some windows manager and OpenGL is either supplied as Mesa (software rasterizer) or they provide proper drivers.
  • FreeBSD: unknown

OpenGL ES is often supported on embedded systems, but OpenGL ES is a different API from regular OpenGL.

How Does It Work On Windows?

All Windows versions support OpenGL.

When you compile an application, you link with opengl32.dll (even on Win64).

When you run your program, opengl32.dll gets loaded and it checks in the Windows registry if there is a true GL driver. If there is, it will load it. For example, ATI's GL driver name starts with atioglxx.dll and nVidia's GL driver is nvoglv32.dll. The actual names change from release versions.

opengl32.dll is limited to 1.1. For GL >=1.2 functions, you get a function pointer with wglGetProcAddress. Examples are glActiveTexture, glBindBuffer, glVertexAttribPointer. wglGetProcAddress returns an address from the real driver in these cases.

The only important thing to know is that opengl32.dll belongs to Microsoft. No one can modify it. You must not replace it. You must not ship your application with this file. You must not ship nvoglv32.dll or any other system file either.

It is the responsibility of the user to install the driver made available from Dell, HP, nVidia, ATI/AMD, Intel, SiS, and whatever. Though feel free to remind them to do so.

How do I tell what version of OpenGL I'm using?

Use the function glGetString(GL_VERSION). This will return a null-terminated string. Do not copy this string into a fixed-length buffer, as it can be fairly long.

The string has a specific format:

 <major version>.<minor version>

Following the minor version can be another '.' with a vendor-specific build number. Following that is entirely vendor-specific information. The format of this information is up to the driver writers.

Alternatively, you can use glGetIntegerv(GL_MAJOR_VERSION, *) and glGetIntegerv(GL_MAJOR_VERSION, *). These require GL 3.0 or greater, however.

Why is my GL version only 1.4 or lower?

There are two reasons you may get an unexpectedly low OpenGL version.

On Windows, you may be a low GL version if, during context creation, you use an unaccelerated pixel format. This means you get the default implementation of OpenGL. Depending on whether you are using Windows Vista or earlier versions of Windows, this may mean you get a software GL 1.1 implementation, or a hardware GL 1.5 implementation.

The solution to this is to be more careful in your pixel format selection.

The other reason is that the makers of your video card (and therefore the makers of your video drivers) do not provide an up-to-date OpenGL implementation. There are a number of defunct graphics card vendors out there. However, of the non-defunct ones, this is most likely to happen with Intel's integrated GPUs.

Intel does not provide a proper, up-to-date OpenGL implementation for their integrated GPUs. There is nothing that can be done about this. NVIDIA and ATI provide good support for their integrated GPUs.

glTranslate, glRotate, glScale

Are these hardware accelerated?

No, there are no known GPUs that execute this. The driver computes the matrix on the CPU and uploads it to the GPU.

All the other matrix operations are done on the CPU as well : glPushMatrix, glPopMatrix, glLoadIdentity, glFrustum, glOrtho.

This is the reason why these functions are considered deprecated in GL 3.0. You should have your own math library, build your own matrix, upload your matrix to the shader.

A list of various libraries is at Alternative Game Libraries.

Fixed function and modern GPUs

Modern GPUs no longer support fixed function. Everything is done with shaders. In order to preserve compatibility, the GL driver generates a shader that simulates the fixed function. It is recommended that all new modern programs use shaders. New users need not learn fixed function related operations of GL such as glLight, glMaterial, glTexEnv and many others.

How to render in pixel space

Setup a certain projection matrix

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glOrtho(0.0, WindowWidth, 0.0, WindowHeight, -1.0, 1.0);
 //Setup modelview to identity if you don't need GL to move around objects for you
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

Notice that y axis goes from bottom to top because of the glOrtho call. You can swap bottom and top parameters if you want y to go from top to bottom. make sure you render your polygons in the right order so that GL doesn't cull them or just call glDisable(GL_CULL_FACE).

Multi indexed rendering

What this means is that each vertex attribte (position, normal, etc) has its own index array. OpenGL (and Direct3D, for that matter) do not support this.

It is up to you the user to adjust your data format so that there is only one index array, which samples from multiple attribute arrays. To do this, you will need to duplicate some attribute data so that all of the attribute lists are the same size.

Quite often, this question is asked by those wanting to use the OBJ file format:

 v 1.52284 39.3701 1.01523
 v 36.7365 17.6068 1.01523
 v 12.4045 17.6068 -32.475
 and so on ...
 n 0.137265 0.985501 -0.0997287
 n 0.894427 0.447214 -8.16501e-08
 n 0.276393 0.447214 -0.850651
 and so on ...
 t 0.6 1
 t 0.5 0.647584
 t 0.7 0.647584
 and so on ...
 f 102//102//102 84//84//84 158//158//158 
 f 158//158//158 84//84//84 83//83//83 
 f 158//158//158 83//83//83 159//159//159 
 and so on ...

The lines that start with an f are the faces. As you can see, each vertex has 3 indices, one for vertex, normal, texcoord.

You will need to do post-processing on OBJ files before you can use them.

See also

glClear and glScissor

glScissor is one of the few functions that effect on how glClear operates. If you want to clear only a region of the back buffer, then call glScissor and also glEnable(GL_SCISSOR_TEST).

Alternatively, if you have used the scissor test and forgot to glDisable(GL_SCISSOR_TEST), then you might wonder why glClear isn't working the way you want to.

Masking

Pay attention to glColorMask, glStencilMask and glDepthMask. For example, if you disable depth writes by calling glDepthMask(FALSE), then all calls to glClear will not clear the depth buffer.

glGetError (or "How do I check for GL errors?)

OpenGL keeps a set of error flags, and each call to glGetError() tests and clears one of those flags. When there are no more error flags set, then glGetError() returns GL_NO_ERROR. So use a little helper function like this to check for GL errors:

  #include <stdio.h>
  #include <GL/gl.h>
  #include <GL/glu.h>

  int checkForGLErrors( const char *s )
  {
    int errors = 0 ;
    int counter = 0 ;

    while ( counter < 1000 )
    {
      GLenum x = glGetError() ;

      if ( x == GL_NO_ERROR )
        return errors ;

      fprintf( stderr, "%s: OpenGL error: %s [%08x]\n", s ? s : "", gluErrorString ( x ), errcnt++ ) ;
      errors++ ;
      counter++ ;
    }
  }

If there is no GL context, glGetError() would return an error code each time it is called since it is an error to call glGetError when there is no GL context. That is the reason why we have added counter < 1000.