Using glut with code blocks in Windows 7 - opengl

i'm a total novice with OpenGL, and I have to compile a file (my first file using opengl), the headers of the file are :
#include <GL/glut.h>
#include <GL/gl.h>
#include <iostream>
I downloaded glut, put the glut.h in the right folder, and put the glut32lib in the right folder too (in Code Blocks).
I also linked glut32.lib in the linker settings.
But i can not compile, i have errors like this :
....\Desktop\OpenGL\OpenGL\prog3.o:prog3.cxx|| undefined reference to `__glutInitWithExit'|
Please can you help me ?
EDIT : Solution foud here : GLUT compile errors with Code::Blocks
All that was needed was #include before including GL/glut.h
I don't know why...

This was my problem. I found solution for this problem in 2 step.
Step 1: follow instructions in this link: Using OpenGL & GLUT in Code::Blocks
Step 2: add #include <GL/glu.h> before #include <GL/glut.h>
Attention: you must create new project, not blank source file. Just follow how to do it in that link.

Related

Including <string> in c++ using Netbeans

Netbeans fails compilation on:
#include <string>
Output says:
main.c:10:18: fatal error: string: No such file or directory
#include <string>
The previous two declarations are included fine:
#include <stdio.h>
#include <stdlib.h>
I have removed all the code afterwards to make sure.
I am using cygwin_64 and it installed as per Netbeans c++ installation manual and shows versions in CLI
I am new to C++ and I know there have been similar questions, but the answers didn't help me.
Just try to create new project and follow these steps:
Click File->Create project.
Choose C/C++, then C/C++ application, click Next.
Enter project name and in the right choose C++ in combobox. Or C++11.

Adding SDL 1.2.15 Framework on XCODE 7: 2 times class main gives error at compilation

This problem has been already asked but after an extensive search on Google I've found no questions related to the 1.2.15 version of SDL with the last version of XCODE so please allow me to post the problem (again) and the solution I've found for those up-to-date version (30th September 2015).
Config:
OSX 10.10.5
XCODE 7.0
SDL 1.2.15
How to reproduce:
Copied the SDL.Framework to /Library/Frameworks as explained on the readme.txt
On XCODE Template > Building settings > Framework Search path as /Library/Frameworks
I included the SDL framework on the main.cpp file as follows:
#include <SDL/SDL.h>
When I try to compile and test I get an error because of a double declaration of class main...
This is the error message:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: _SDL_main)
This how I solved it:
I checked and saw that SDL.h is including all the following files:
#include "SDL_main.h"
#include "SDL_stdinc.h"
#include "SDL_audio.h"
#include "SDL_cdrom.h"
#include "SDL_cpuinfo.h"
#include "SDL_endian.h"
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_loadso.h"
#include "SDL_mutex.h"
#include "SDL_rwops.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "SDL_video.h"
#include "SDL_version.h"
#include "begin_code.h"
One of them is SDL_main.h and on that file we see:
#define main SDL_main
This line is producing a conflict with the class main on main.cpp, commenting that line on SDL_main.h or commenting the line #include "SDL_main.h" on SDL.h solves the issue. I'm a noob on C++ (I just learn it at University many years ago) but from other languages I know that "hacking" a library is a very bad practice... though it seems to be a particular compatibility problem with MAXOSX and I really want to use XCODE...
Please correct and comment, justify yes or no, as I'm on a learning process.
Cheers!
I've resolved the problem with #undef main before the declaration of the main function.

C++ project build, but IDE shows error

Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.

OpenGL SOIL Undefined reference to glBindTexture, glTexImage2d, etc

I'm using C++ and Opengl, and I'm trying to use SOIL, but when I compile, I get undefined reference to glBindTexture, glTexImage2D, etc. However, this is only coming from SOIL.c, not my own source code. This is what the error produces:
http://pastebin.com/sKrQaBhz
My graphics card is NVIDIA GeForce GTX 680 and my drivers are fully updated. I have everything linked and I'm using premake to manage my project. I'm developing on a linux machine, however, I'm trying to cross compile it onto my windows machine, which gives this error. If I compile it on linux, it's completely fine. This is my premake4.lua file:
http://pastebin.com/T4hsbdz0
My include files is this:
#include "opengl/gl_core_3_3.hpp"
#include <GLFW/glfw3.h>
#include <SOIL/SOIL.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "loadshader.hpp"
I'm using mingw32 to compile my code. Before I was using SOIL, everything was fine. I downloaded SOIL from their webpage at lonesock.net, which I then copied over the libSOIL.a and their include files, but it just doesn't work.
Links order matters for g++.
Try this order:
links { "SOIL", "glfw3", "opengl32", "gdi32", "glu32" }
(edit: fixed the OP answer according to the duplicated question in Premake forum: http://industriousone.com/topic/how-use-premake-compile-static-library)
Looking at SOIL homepage, they said that it must be linked staticly. So, instead of using dynamic linking ('-l' in gcc compiler), try to specify the full path of the library.
This post illustrate what I want to say: https://stackoverflow.com/a/4156190/2293156
gcc -lsome_dynamic_lib some_static_lib.a code.c

OpenGL Linking error? Unresolved external glCreateShader()

I'm working on an OpenGL program to test out shaders and trying to compile them. However, the call to glCreateShader() (and other shader calls like glDeleteShader) give the following error:
(this error is from glCreateShader())
Error 3 error LNK2001: unresolved external symbol _pglCreateShader
I'm using Visual Studio 2012 and on windows 7. Got one of the latest nvidia cards including the latest drivers so can't be my OpenGL version.
I'm using the glTools header files for all the helper functions for the OpenGL Superbible 4th edition. Not sure if there is an error in using these files?
I'll post my includes in case this could be of any help as well.
#pragma once
#include <Windows.h>
// Basic C++ includes
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
// OpenGL specific and GUI includes
#include "shared/gltools.h"
#include "shared/math3d.h"
#include <SOIL.h>
And linker options:
soil.lib;opengl32.lib;gltools.lib;
Oké, the problem has been solved thanks to the answers:
I edited my glTools.h to include 'gl/glew.h' instead of "glee.h", added a ;glew32.lib option to my linker and added glewInit() before entering the main loop. I've also added the GLEW libs,dlls and includes into the appropriate folder and all the functions work like they should! :)
Grab a copy of GLEW to handle extension loading.
Doing it by hand is...annoying.
On Windows, you use WGL, and when using WGL you can't just link against the GL functions directly. All the functions you get are these; you're supposed to dynamically grab the pointer to the GL entry point you want with wglGetProcAddress (as in here) before you can use them.
Basically, OpenGL on Windows is a PITA if you do the GL entrypoint function pointer loading manually. It's much easier to use a utility library to grab the pointers for you, such as GLEW.