OpenGL functions are undefined in VS2012 express - c++

I'm attempting to use some OpenGL functions in Visual Studio 2012 express, my code looks like this:
#include <Windows.h>
#include <iostream>
#include <gl/GL.h>
#include <fstream>
void saveScreen()
{
//code to define some variables, nWidth, nHeight and Buffer.
glreadbuffer ( GL_BACK ); //which buffer we are reading from.
glreadpixels ( 0, 0, nWidth, nHeight, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *Buffer);
//do something with buffer data
return;
}
According to internet research, my code is correct, apart from glreadpixels apparently expects more expressions and )'s, but i think i can work that out myself.
When i try to compile and run i get errors saying both glreadbuffer and glreadpixels are undefined. I cant find anything that tells me what to do apart from #including windows.h and gl/gl.h and OpenGL should work.
Thanks in advance for any help :)
Edit:
Thanks for replying, I added these lines to the Additional dependancys of the linker:
opengl32.lib
glu32.lib
and properly capitalised the function calls
That seems to have solved the problem.

The functions glreadbuffer() and glreadpixels do not exist in OpenGL. The API uses CamelCase function name style, so these function names are spelled glReadBuffer() and glReadPixels().

This is how you correctly link in visual studio 12:
The first thing you create is a folder somewhere called "dev" (or really any name). In that folder you extract "freeglut"(only if you want a windowing toolkit) and "glew" (the openGL extension wrangler, this loads the gl functions).
After that you open a new project in VS12 and rightclick on the project->properties
Under VC++ properties click on "Include directories" and add the path to your dev/glew/include folder and your dev/freeglut/include. Make sure your path is 100% correct!
Then click on "Library directories" and add these 2 paths: dev/glew/lib and dev/freeglut/lib.
Then go to C/C++ and click on additional include directories and add these 2 paths:dev/glew/include and dev/freeglut/include.
Then go to linker and add the lib folders in "additional library directories" this is a tricky one because you need to link to the correct version: \dev\glew\lib\Release\Win32
Then try your code again, if that doesn't work, try source code from the internet.
Also if you copied the folders without changing there name you should include "GL/glew.h"
These steps are required for each project that uses openGL.

Related

Problems with SFML loadFromFile command

I am trying to get a graphical representation of a chess-board with SFML 2.0. The problem is that I simply cannot load a texture, the command loadFromFile does not work and I don't know why. I already searched the web, also here in Stack Overflow but I did not find a solution.
What I did right now:
Setting all the dependencies for includes and libraries, .dll's and .libs
Changing text format from unicode to multibyte.
Copying the .dll's into the working folder (there was an error that visual studio couldnt find the dlls even though I linked them in the project)
Using the whole path for the image file
using the LoadFile-command with 2 arguments (even though the second one is optional I guess)
Changing runtime library from MDd to MD (trying to get it work in release mode)
Not linking all libraries, but only the ones with a ....-d.lib ending (as supposed in another Stack Overflow thread)
I use Windows 7, Visual Studio Version 15.3.3
This is my code:
#include <SFML/Graphics.hpp>
#include <time.h>
#include <iostream>
int main() {
sf::RenderWindow window(sf::VideoMode(437, 437), "MattseChess!");
sf::Texture t1;
if (!t1.loadFromFile("C:/Users/Mattse/source/repos/Chess/Chess/images/figures.png")) {
std::cout << "Error loading texture" << std::endl;
}
return 0;
}
What shall I try out next?
You should always open files with a relative path ("images/figures.png"). It's relative from the executable.
And check with an other PNG images to see if it does not come from the image that SFML cannot load for any reasons (and try gimp to reexport it with different options like interlacing for example)
I'm guessing (from the C:\Users\ part) you are on a Windows system.
While Windows should support slashes as path separator, the official path separator in Windows is a backslash. It needs to be escaped in C++, so your full path would be:
"C:\\Users\\Mattse\\source\\repos\\Chess\\Chess\\images\\figures.png"
Problem fixed, it was in fact the case that I forgot to delete one library in the linker->input settings. I only have the ones with a -d ending now, even the ones which have NO -d equivalent got deleted.
List of linked libraries:
sfml-audio-d.lib
sfml-graphics-d.lib
sfml-main-d.lib
sfml-network-d.lib
sfml-network-s-d.lib
sfml-system-d.lib
sfml-system-s-d.lib
sfml-window-d.lib
sfml-window-s-d.lib

Visual Studio Include Dll Child Project Header Issue

I had a problem including a dll within visual studio the other day, and thought that I had solved all my problems, it turns out, however, that I did not. My problem is odd, too, because one option works, while the other does not. The behavior I am experiencing is a little strange, but I will try to explain it as best as I can. First, here is some code of my attempts(one of which works) to include a header from the dll I created:
#include <QtWidgets/QApplication>
#include <QMainWindow>
/*
This below works; it seems to be stepping backwards out of the
project and into the folder of the dll project.
*/
#include "../ArclightFramework/GameWindow.h" // This works.
/*
Below does not work, even though the path has been set in the
additional directories field of the project. Oddly, though, I
do get intellisense for the path the below.
*/
#include "ArclightEngine/ArclightFramework/GameWindow.h" // Does not work.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GameWindow f;
f.show();
return a.exec();
}
The first include works perfectly fine, and I can live with basing all my future includes off it. However, does anyone know why the second include does not work? And here is what I mean by "Does not work."
1>------ Build started: Project: ArclightEngine, Configuration: Debug Win32 ------
1> main.cpp
1>main.cpp(13): fatal error C1083: Cannot open include file: 'ArclightEngine/ArclightFramework/GameWindow.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
And here is even a picture of the same mouse over error:
You see, the strange thing is, I DID include the path to my "Additional import directories"; here is a picture:
And here is that directory, and the full path showing that everything SHOULD be found correctly.
My question is quite simple. Why can visual studio not find the include files?
Update: Here is another picture showing how Intellisense is offering completion of the include path, but again, it does not work afterwards!
Another update:
Alright, so I tried something new. This time instead of adding the absolute path to the Additional Include field, I added: "$(ProjectDir)../../" Once again, Intellisense offers completion for this path and the headers within it. But it does not recognize the files itself afterwards, but they do exist and the path is perfect. My path, using the macro above, would transform my include path to: "ArclightEngine/ArclightFramework/BLAH.h"
Here is a new picture showing the path I included:
I don't understand what the difference is between what I have done and the path that is working which is "#include "../ArclightFramework/GameWindow.h""
ALSO, apparently this include path also works now:
"#include "/Users/Krynn/Desktop/ArclightEngine/ArclightEngine/ArclightFramework/GameWindow.h""
TL;DR
All I want is to be able to type "#include "ArclightEngine/ArclightFramework/blah.h"
You've said a user include is:
C:\Users\Krynn\Desktop\ArclightEngine
And you're trying to include:
"ArclightEngine/ArclightFramework/GameWindow.h"
Thus the first path VS will try as you've used quotes rather than angle brackets is:
C:\Users\Krynn\Desktop\ArclightEngine\ArclightEngine\ArclightFramework\GameWindow.h
Which is simply both paths added together, so that's never going to work.
Hence including:
"../ArclightEngine/ArclightFramework/GameWindow.h"
Becomes:
C:\Users\Krynn\Desktop\ArclightEngine\..\ArclightEngine\ArclightFramework\GameWindow.h
Which becomes:
C:\Users\Krynn\Desktop\ArclightEngine\ArclightFramework\GameWindow.h
Hence this works. So another option should be to include:
ArclightFramework\GameWindow.h
Update:
Looks like your real problem was that you updated the configuration of "Release Win32" but you where building "Debug Win32" which has different settings. When updating setting that apply to all configurations and platforms (such as include paths) be sure to select "all configurations" and "all platforms" from the combo boxes.

How to run a simple cpp file that requires QT?

I have QT 5.1.1 installed on my machine, but I'm having some troubles using it. I'm trying to run the following simple program that requires QT:
//Playing Video
#include "cv.h"
#include "opencv2\objdetect\objdetect.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\features2d\features2d.hpp"
#include "opencv2\calib3d\calib3d.hpp"
#include "opencv2\nonfree\nonfree.hpp"
#include "highgui.h"
#include <openbr\openbr_plugin.h>
using namespace cv;
static void printTemplate(const br::Template &t)
{
const QPoint firstEye = t.file.get<QPoint>("Affine_0");
const QPoint secondEye = t.file.get<QPoint>("Affine_1");
printf("%s eyes: (%d, %d) (%d, %d)\n", qPrintable(t.file.fileName()), firstEye.x(), firstEye.y(), secondEye.x(), secondEye.y());
}
int main(int argc, char *argv[])
{
br::Context::initialize(argc, argv);
// Retrieve classes for enrolling and comparing templates using the FaceRecognition algorithm
QSharedPointer<br::Transform> transform = br::Transform::fromAlgorithm("FaceRecognition");
QSharedPointer<br::Distance> distance = br::Distance::fromAlgorithm("FaceRecognition");
// Initialize templates
br::Template queryA("../data/MEDS/img/S354-01-t10_01.jpg");
br::Template queryB("../data/MEDS/img/S382-08-t10_01.jpg");
br::Template target("../data/MEDS/img/S354-02-t10_01.jpg");
// Enroll templates
queryA >> *transform;
queryB >> *transform;
target >> *transform;
printTemplate(queryA);
printTemplate(queryB);
printTemplate(target);
// Compare templates
float comparisonA = distance->compare(target, queryA);
float comparisonB = distance->compare(target, queryB);
// Scores range from 0 to 1 and represent match probability
printf("Genuine match score: %.3f\n", comparisonA);
printf("Impostor match score: %.3f\n", comparisonB);
br::Context::finalize();
return 0;
}
It also requires OpenCV 2.4.6.1 and OpenBR, but that's not the problem.
All the definitions (variables and functions) in the above code that are related to QT are undefined. I've tried to find the relevant h files in QT folder and to include them, but that did not succeed since I couldn't fine qtcore.h (but a different file named qtcore with lot's of includes that I don't now how to use). I've tried to add QT "include" directory under "additional include directories" in the project properties but that didn't work either. I've also tried to add QT "lib" folder under "additional library directories" but that also did not work.
Basically, I tried everything I could think of. Can someone please explain how to I use those QT definitions? I'm really stuck and I could use any help given.
Thanks,
Gil.
(Optional) Update to Qt 5.2.
Start Qt Creator.
Create a new Qt Widgets Application project. You can give the class/files random names, it doesn't matter. Uncheck the "generate form" option, as you don't need any forms.
Remove all the files other than main.cpp from the project. You do this by right-clicking on them in the project tree on the left and choosing Remove File.
Copy-paste your code into main cpp. Make sure you completely replace main.cpp's contents, the default contents shouldn't be there anymore.
Add the opencv library to the project. Right-click on the project's root, select "Add Library", and go from there.
Re-run qmake by right-clicking on the project root and selecting "Run qmake".
Build and run the project by pressing Ctrl-R (Cmd-R on mac).
Qt uses a (non-standard) custom toolchain that has to run before the Qt-dependent code can be compiled. I've never tried using Qt outside of QtCreator, but if you really need Qt I'd suggest you use the QtCreator IDE; if you're not using it already of course. It's a very decent IDE, even for non-Qt projects.
Also, if you haven't done so already, make sure the Qt SDK is installed; the headers alone are not enough. QtCreator by itself is also not enough, you'll need the SDK. If you don't feel like doing so, my suggestion would be to look at Poco. It's not a 1:1 replacement for Qt, but a very mature framework nevertheless.

how to set Windows file permissions in Qt/C++

In my Qt 4.7.4 x64 C++ app I'm building in Qt Creator 2.5.0, I want to give full access to everyone for a file. I'm using QFile::setPermissions, which I believe works fine for Mac and Linux, but it doesn't work for Windows. According to Qt setPermissions not setting permisions, I should use
SetNamedSecurityInfoA("C:\file.txt", SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL);
But I don't know what to #include to make it work. I tried:
#ifdef Q_WS_WIN
#include "Windows.h"
#endif
based on what I found here. But when I compile, I get C3861: 'SetNamedSecurityInfo': identifier not found (among some other new errors).
When I mouse over my #include "Windows.h", I get the tooltip: C:\Program Files\Microsoft SDKs\Windows\v7.0\include\Windows.h, and I can press F2 and jump to that file. We have other files in our project that include that same Windows.h, and they compile fine.
How do I set file permissions on Windows for everyone to read/write? If SetNamedSecurityInfo is what I want (I guess SetNamedSecurityInfoW in my case since my users may be running OS's in any language), what do I #include to be able to use it? Better yet, how do I figure out what to #include, so I know for next time I need to use the Windows API?
SetNamedSecurityInfo
Header
Aclapi.h
Library
Advapi32.lib
DLL
Advapi32.dll
A quick search on Google would probably have had this page among it top hits. There you can see which header file and library you need.

Windows/opengl glext.h build issue

So I'm trying to bring a c++ project using Qt and OpenGL written and compiled on a Linux machine over to my Windows 7 machine at home, but I'm running into some difficulty. First I learned that some gl things (like GL_TEXTURE0) were no longer defined because gl.h doesn't define them for windows. Also, the glext.h that I have does not define some functions like glActiveTexture. Both of these issues I found could be solved by bringing in a newer glext.h.
My most immediate issue seems to be that I'm not bringing it in correctly. If I do:
#define GL_GLEXT_LEGACY //should prevent old glext.h from being included
#define GL_GLEXT_PROTOTYPES //should make glActiveTexture be defined
#include <qgl.h>
#include "glext.h" //local up-to-date glext.h
#include <QGLShaderProgram>
then make tells me that I have undefined references to glActiveTexture. If I include QGLShaderProgram before glext.h, then I still have that problem, but make also warns me that I am redefining quite a few things that are defined in both QGLShaderProgram and glext, so I know the latter file is being included. Any help would really be appreciated.
You are on a right path, but like Nick Meyer wrote, you need to get pointers to the functions at runtime.
There is a nice and clean example already in Qt installation directory, at least since 4.6. Check "Boxes" from "demos"-directory. There is glextensions.h/cpp that takes care of those required functions in Qt-way, using Qt's QGLContext etc.
If you're lazy like me, just hop over to
http://glew.sourceforge.net
and use that, no need to fiddle around with different header files and manually retrieving function pointers. It's as simple as
/* in every source file using OpenGL */
#include <GL/glew.h>
and
/* for each OpenGL context */
if( createGLContext(...) == SUCCESSFULL )
glewInit()
If you're using Qt you should probably use qmake - and just add
QT += opengl
to your qmake project file.