Jump to content

Getting GPU info from OpenGL using C++ for Windows

Shammikit

i want to get gpu information such as vendor name,model of the gpu, the clock speeds and other info. i have already found this code online and im getting this error which i have attached in images. im new to c++ and im very new to OpenGL so i do not understand the error codes. i did a search about the error but couldnt find a solution or any tips to resolve it.  i have checked if i have these files (GL/gl.h, GL/glew.h, GL/freeglut.h) in my C:\Qt\Qt5.5.1\Tools\mingw492_32\i686-w64-mingw32\include\GL directory and they are there. any guidance would be very helpful. thank you 

 

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

int main(int argc, char **argv)
{
        glutInit(&argc, argv); /* create opengl context */
        glutInitContextVersion(4, 4); /* use version 4.4 */
        /* there's no main loop, so the window will close immediately */
        glutCreateWindow("You won't see this window");

        /* we can now get data for the specific OpenGL instance we created */
        const GLubyte *renderer = glGetString( GL_RENDERER );
        const GLubyte *vendor = glGetString( GL_VENDOR );
        const GLubyte *version = glGetString( GL_VERSION );
        const GLubyte *glslVersion = glGetString( GL_SHADING_LANGUAGE_VERSION );
        GLint major, minor;
        glGetIntegerv(GL_MAJOR_VERSION, &major);
        glGetIntegerv(GL_MINOR_VERSION, &minor);
        printf("GL Vendor : %s\n", vendor);
        printf("GL Renderer : %s\n", renderer);
        printf("GL Version (string) : %s\n", version);
        printf("GL Version (integer) : %d.%d\n", major, minor);
        printf("GLSL Version : %s\n", glslVersion);
        return 0;
}

 

er2.JPG

er1.JPG

Link to comment
Share on other sites

Link to post
Share on other sites

If you're doing this for fun, I unfortunately cannot help you.

 

If you're just curious about the specs of your GPU, you can download and install GPU-Z that'll tell you everything about it.

Quote or tag me( @Crunchy Dragon) if you want me to see your reply

If a post solved your problem/answered your question, please consider marking it as "solved"

Community Standards // Join Floatplane!

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Shammikit said:

<snip>

Same problem as in your previous post, linker error, the linker cannot find the implementation of those functions because you're not linking the required libraries. (glut32 for starters).

 

I suggest you start at the beginning and study how the c++ build process works first, so you understand the difference between compilation and linking. It looks like you don't understand what is happening. The headers only provide the declaration of those functions and that's enough for the compiler, who does not care about the actual implementation. As such your program compiled successfully, otherwise you'd never had made it to the linker step.

The linker step is where everything is tied together and it needs the actual implementation of those functions.

 

If you're working with QT creator and MinGW you should be able to edit your project's .PRO file to add libraries to the link process by adding the line:

LIBS += -lx

Where x is the library name:

LIBS += -lglut32

You can add such a line for each library you want to add, providing you have the correct version of the library file in your linker's search path.

Link to comment
Share on other sites

Link to post
Share on other sites

18 hours ago, Unimportant said:

Same problem as in your previous post, linker error, the linker cannot find the implementation of those functions because you're not linking the required libraries. (glut32 for starters).

 

I suggest you start at the beginning and study how the c++ build process works first, so you understand the difference between compilation and linking. It looks like you don't understand what is happening. The headers only provide the declaration of those functions and that's enough for the compiler, who does not care about the actual implementation. As such your program compiled successfully, otherwise you'd never had made it to the linker step.

The linker step is where everything is tied together and it needs the actual implementation of those functions.

 

If you're working with QT creator and MinGW you should be able to edit your project's .PRO file to add libraries to the link process by adding the line:


LIBS += -lx

Where x is the library name:


LIBS += -lglut32

You can add such a line for each library you want to add, providing you have the correct version of the library file in your linker's search path.

i have already done this. i copied the glut32.lib for "C:\Qt\Qt5.5.1\Tools\mingw492_32\i686-w64-mingw32\include" directory and i have added the library to the .pro file as shown in the image. the errors point to these 2 lines in the code

glutInitContextVersion(4,4); /* use version 4.4 */

const GLubyte* vendor = glGetString(GL_VENDOR);

i do not know what version of glut32.lib it is. idk even if there are versions for them. if im tyring to get gpu details using this in windows what version should i look for ?

g.JPG

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Shammikit said:

i have already done this. i copied the glut32.lib for "C:\Qt\Qt5.5.1\Tools\mingw492_32\i686-w64-mingw32\include" directory and i have added the library to the .pro file as shown in the image. the errors point to these 2 lines in the code


glutInitContextVersion(4,4); /* use version 4.4 */

const GLubyte* vendor = glGetString(GL_VENDOR);

i do not know what version of glut32.lib it is. idk even if there are versions for them. if im tyring to get gpu details using this in windows what version should i look for ?

g.JPG

The include directory is where the compiler searches for headers, it's definitely not a location the linker will search for libraries.

It looks like you need opengl32.lib aswell for the glGetString function.

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Unimportant said:

The include directory is where the compiler searches for headers, it's definitely not a location the linker will search for libraries.

It looks like you need opengl32.lib aswell for the glGetString function.

if i have the lglut32.lib file in a folder called GL in C drive is it correct if i write the linker like this

 

LIBS += -LC:\GL\lglut32
Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, Shammikit said:

if i have the lglut32.lib file in a folder called GL in C drive is it correct if i write the linker like this

 


LIBS += -LC:\GL\lglut32

 

LIBS += -LC:\GL\ -lglut32

 

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, Unimportant said:

 

LIBS += -LC:\GL\ -lglut32

thanks after putting this it lost alot of errors. now there's only one error and i believe its for not including the opengl32.lib. i have been searching to download this at several places and i have also tried searching if its available in my PC itself but i had no luck. i have already gone through the opengl website too but didnt find anything to download from there too. could you please direct me to a place to download if there is any? 

2.JPG

Link to comment
Share on other sites

Link to post
Share on other sites

59 minutes ago, Shammikit said:

thanks after putting this it lost alot of errors. now there's only one error and i believe its for not including the opengl32.lib. i have been searching to download this at several places and i have also tried searching if its available in my PC itself but i had no luck. i have already gone through the opengl website too but didnt find anything to download from there too. could you please direct me to a place to download if there is any? 

2.JPG

I quickly unpacked mingw on a virtual machine and it looks like they call the library 'libopengl32' in stead of plain 'opengl32'. You can try that. (But it looks like the required library files are included with mingw)

LIBS += -llibglut32 -llibopengl32 

perhaps ?

 

EDIT: scratch that, it seems the linker automatically prepends 'lib',so I think it should be:

LIBS += -lglut32 -lopengl32 

Both files come included with mingw, but mingw uses a .a extention in stead of .lib.

It should work by itself, as the files are included. If it does not I guess something is wrong with your mingw installation/settings (?) But if you want to search the files on your harddisk search for "libopengl32.a" and "libglut32.a".

Link to comment
Share on other sites

Link to post
Share on other sites

12 minutes ago, Unimportant said:

I quickly unpacked mingw on a virtual machine and it looks like they call the library 'libopengl32' in stead of plain 'opengl32'. You can try that.

i managed to find a libopengl32 in the lib folder in mingw. it is a file with extension ".a" . i took a copy of it and pasted it to a folder called GL in my C drive and added it to the linker like this:

LIBS += -LC:\GL\ -llibopengl32

 

but i got an error saying -llibopengl32 cannot be opened. is there a different way i should include it

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Shammikit said:

i managed to find a libopengl32 in the lib folder in mingw. it is a file with extension ".a" . i took a copy of it and pasted it to a folder called GL in my C drive and added it to the linker like this:


LIBS += -LC:\GL\ -llibopengl32

 

but i got an error saying -llibopengl32 cannot be opened. is there a different way i should include it

oh wait i changed it extension to .lib then it ran

Link to comment
Share on other sites

Link to post
Share on other sites

25 minutes ago, Unimportant said:

 


LIBS += -lglut32 -lopengl32 

 

sorry for taking such a long time to leave any feedback. i included it like this, i got a error saying undefined reference to `_imp__glutInitContextVersion@8' pointing to this code:

  glutInitContextVersion(4,4); /* use version 4.4 */

 

what i did was i removed this as i saw in stackoverflow if i remove it, then the version would be identified automatically. the program did run but it gave no output. im  using cout to get the output. to check if cout is working i wrote this basic cout statement:

   cout << "Hello, World!";

and even that didnt work!! for some reason cout stops working after typing all those codes.i commented everything made a new main method and wrote this : cout << "Hello, World!"; and that worked. all this time i was trying to fix this and get a output to see if it works

 

Link to comment
Share on other sites

Link to post
Share on other sites

@Unimportant sorry to trouble you once again. Decided to call u as im still stuck. i have a problem where im unable to display what i have got from the above code. im running it on a QT widget application now and im trying to display the output in a Qlabel. i have tried it like this:

const GLubyte* vendor = glGetString(GL_VENDOR);
ui->label->setText(vendor);

and also this way:

QString a = glGetString(GL_VENDOR);
ui->label->setText(a);

 and both of them resulted in errors like this : invalid conversion from 'const GLubyte* {aka const unsigned char*}' to 'const char*' [-fpermissive] QString a = glGetString(GL_VENDOR);

 

im guessing its asking me to convert GLubyte to a string so that it can display it in the label. i have done some searching about it but havent managed to figure out anything.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

22 hours ago, Shammikit said:

<snip>

const GLubyte* glVendorCString = glGetString(GL_VENDOR);

//glGetString returns a null pointer on error.
if (!glVendorCString)
{
	//Handle error.
}

//cast from const unsigned char* to const char*
const QString glVendorString( reinterpret_cast<const char*>(glVendorCString) );
ui->label->setText(glVendorString);

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×