Basic Open GL/GLUT Issue - opengl

I am studying graphics and currently using OpenGL with GLUT. Doing my editing in codeblocks and using an online tutorial located at lighthouse3d. I am using the main method declared on that page however it will not let me compile. The error message consists of the main method not returning an int, I have "played" with the code enough to say I am confused. The GLUT Library is installed, and I do not see where the error is coming from.
Thank you,
Zach Smith

You probably have a method like this:
void main(int argc, char** argv) {
// The code...
}
Change it to this:
int main(int argc, char** argv) {
// The code...
return 0;
}

The problem is that you are not linking the needed libraries.
Go to the project properties by right clicking on the project icon in the 'Solution Explorer' and click on 'Properties'. Then go under 'Configuration Properties' -> 'Linker' -> 'Input' and add the following libraries to the 'Additional Dependencies' field:
opengl32.lib glut32.lib glu32.lib
Rebuild your project and all should be fine!

Related

Struggle with QGIS C++ API

I'm trying to create a simple application using QGIS SDK. But currently, I'm stuck with API at very beginning stage.
belows are the env.
Windows 7
MSVC 2015
QGIS SDK (downlaod by OSGeo4w) include:
qgis-dev(3.2.3)
Qt5(5.9)
here is the OSGeo4w directory
here is the OSGeo4w/app directory
And start by create an empty project, property settings:
C/C++ -> General -> Additional Include Directories
C:\OSGeo4W\apps\Qt5\include
C:\OSGeo4W\apps\Qt5\include\QtCore
C:\OSGeo4W\apps\Qt5\include\QtGui
C:\OSGeo4W\apps\Qt5\include\QtWidgets
C:\OSGeo4W\apps\Qt5\include\QtXml
C:\OSGeo4W\apps\qgis-dev\include
C:\OSGeo4W\include
Linker -> General -> Additional Library Directories
C:\OSGeo4W\apps\Qt5\lib
C:\OSGeo4W\apps\qgis-dev\lib
Linker -> Input -> Additional Dependencies
qtmaind.lib
Qt5Cored.lib
Qt5Guid.lib
Qt5Widgetsd.lib
qgis_core.lib
qgis_app.lib
qgis_gui.lib
The test code is quite simple:
main.cpp
#include <QtWidgets/QApplication>
#include <qgsapplication.h>
int main(int argc, char *argv[])
{
QgsApplication a(argc, argv, true);
// QgsApplication::setPrefixPath("C:/path/to/OSGeo4W64/apps/qgis", true);
// QgsApplication::initQgis();
// ImageViewer w;
// w.show();
return a.exec();
}
however, errors occured when I build it,
(1)no instance of constructor "QgsMapUnitScale::QgsMapUnitScale" matches the argument list (qgsrendercontext.h)
(2)"M_PI": undeclared identifier (qgsabstractgeometry.h)
here is the build error messages
Could anyone give me a suggestion?I have some difficulties to understand how the API should work and there is really few doc. and resource about
QGIS C++ developement on internet, even on QGIS offical website.
I appreciate any help, thanks.

Linking google test to your main project

I am new to the gtest. I have followed a tutorial how to set it up in the VS 2105.
But all that I could find talked about how to build and link gtest.
I am passed that level. The code below runs and passes the first dummy test.
#include "gtest/gtest.h"
TEST(VI, simple) {
EXPECT_EQ(false, false);
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
std::cin.get();
return 0;
}
My question:
How do I exactly hook it up to my project that I want to test?
Both gtest project and my "code" project are in the same solution.
As far as I understood from reading numerous tutorials, I need 2 things:
1) to include my .h of the class I am about to test (easy and done)
2) To compile my "code" project into a static lib and then hook up
the lib to gtest project so I can create and test objects from the
"code" project.
I am struggling with the point 2. How exactly do I go about it?
Thank you for help in advance.
Add a new empty Win32 project to your solution, in its properties select Project Type "static library (.lib)"
Move all your sources except the main() function to that project
Add a reference to the .lib project to both your main application project and the google test project

C++ header file in Visual Studio

Okay. So I've got a simple question. If I ask it in the wrong place, please correct me. What I want to ask is, why Visual Studio gives me this:
#include "stdafx.h"
int main()
{
return 0;
}
everytime I create a new project? (I know I can select Empty Project, and add mine .cpp file by myself, but I'm just curious. It says #include <stdio.h> and #include <tchar.h>. So what is it for? Are you all using it or something?
And P.S - why there is no (int argc, char** argv) in main declaration? (on my coding course in college I've learned that there may be _tmain(int argc, _TCHAR* argv), when creating something in VS)
Okay. So I've got a simple question. If I ask it in the wrong place, please correct me. What I want to ask is, why Visual Studio gives me this:
...
Well, it depends a bit on the project type you've been choosing from the wizard. Looks like the standard template for a console project.
#include "stdafx.h"
is prepended for any type of translation unit by the wizard. It supports the precompiled header optimizaton mechanism.
why there is no (int argc, char** argv) in main declaration?
Because the template provides the minimum for a valid main() entry routine definition.
When creating a new Win32 project, Visual Studio automatically adds a precompiled header "stdafx.h" to your project, even if you unchecked the 'Empty Project' checkbox.
If you want to disable this, go to your project configuration properties -> C/C++ -> Precompiled Headers and select 'Not Using Precompiled Headers'.
Working with precompiled headers see: https://stackoverflow.com/a/4726838.
And P.S. look at -> https://stackoverflow.com/a/4207223
The precompiled header is for speeding up compile times by compiling the contents of your most frequently included headers only once and then reusing the compile results. You can change its name if you want.

OpenGL installation/initialization

I am trying to write some openGL code in visual studio 2012. I've looked over the internet to try and get this set up properly, and I can't seem to solve this.
#include <gl\GL.h>
#include <gl\GLU.h>
#include <gl\glut.h>
int main(int argc, char**argv){
glutInit(&argc, argv);
}
The glutInit line does not work, saying glutInit is not defined. Can someone please walk me through how to set this up properly in VS 2012? I've done things like this before in 2010, and would really like to just start working on my project.
You add the glut directory to the VC++ directories, here:
Then you need to add the name of the library under the Additional Dependencies:

Linking Qt in CodeLite

I'm not sure why this is, but 99% of the problems I have with programming in C++ have to do with the gcc linker.
I want to link the Qt library to a project in CodeLite. This is the code I have so far:
#include <QApplication>
int main(int argc, char *argv[])
{
return 0;
}
When I compile, I get the error
/Users/andrew/Dev/C++/COSC 102/elitecod/main.cpp:1:24: error: QApplication: No such file or directory
I have Qt installed (with Homebrew, Mac OS X Lion) in /usr/local/include. Why is this happening, and how can I fix this problem?
The error indicates it can't find the file QApplication. You need to add the Qt 'include' directory to the list of places the compiler should look for it and other header files.
A brief google seems to indicate you may have other problems with Qt, you might want to keep this link handy.