OPENGL tutorials - which ones work with codeblocks?

I have started an OpenGL project, and was originally going to start following tutorials in it. Trouble is, none of the code from any of them I've found works, there are always tons of errors!

I have tried:
http://en.wikibooks.org/wiki/OpenGL_Programming#The_basics_arc

and

http://www.arcsynthesis.org/gltut/

These were recommended as good places to start but codeblocks has no idea what they are. It gives loads of errors, like it doesnt understand ANY of it. Are the above tutorials not written in C++ so no good for codeblocks?

I believe OpenGL is installed correctly as codeblock's "new project" menu has opengl, glut and glfw options available. So what is the problem?

> Trouble is, none of the code from any of them I've found works, there are always tons of errors!
That is not very informative. We need to know the errors, the code that they refer to and what were you doing that cause them (your build command)
Ok heres the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Using the standard output for fprintf */
#include <stdio.h>
#include <stdlib.h>
/* Use glew.h instead of gl.h to get all the GL prototypes declared */
/* #include <GL/glew.h>
/* Using the GLUT library for the base windowing setup */
#include <glut.h>
/* ADD GLOBAL VARIABLES HERE LATER */

int init_resources(void)
{
  /* FILLED IN LATER */
  return 1;
}

void onDisplay()
{
  /* FILLED IN LATER */
}

void free_resources()
{
  /* FILLED IN LATER */
}

int main(int argc, char* argv[])
{
  /* Glut-related initialising functions */
  glutInit(&argc, argv);
  glutInitContextVersion(2,0);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
  glutInitWindowSize(640, 480);
  glutCreateWindow("My First Triangle");

  /* Extension wrangler initialising */
  GLenum glew_status = glewInit();
  if (glew_status != GLEW_OK)
  {
    fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
    return EXIT_FAILURE;
  }

  /* When all init functions run without errors,
  the program can initialise the resources */
  if (1 == init_resources())
  {
    /* We can display it if everything goes OK */
    glutDisplayFunc(onDisplay);
    glutMainLoop();
  }

  /* If the program exits in the usual way,
  free resources and exit with a success */
  free_resources();
  return EXIT_SUCCESS;
}


And here's the errors:

http://imgur.com/0Fdg6DE
(sorry its an image but you cant copy and paste from the build log)

My build command is F9, I just press that and it runs? (or should)
1
2
3
/* Use glew.h instead of gl.h to get all the GL prototypes declared */
/* #include <GL/glew.h>
/* Using the GLUT library for the base windowing setup */


Read that. See anything wrong there?
Yeah i see that but I already installed GLUT. I vagely remember reading that these were both different types of opengl and don't go well together?
I vagely remember reading that these were both different types of opengl and don't go well together?


Neither one of these is a "type of opengl." They are libraries that do different things. You're attempting to use both, but you've commented out the include for glew, thus the error message.

http://stackoverflow.com/a/19719329

Ok i see, so can you tell me:

A) where to download glew
B) Step-by-step, how to install which bits where.

I am google searching it now, but im kind of in the same boat as this guy:
http://forums.codeblocks.org/index.php/topic,16656.msg113071.html

There doesnt seem to be any tutorial and all the links are on about either installing it in different software, or installing other software along with it.... very confusing!
Actually make that for both GLEW and GLUT because I followed the install instructions for GLUT and the include line doesnt give an error, but then I get "undefined reference" on basically every "_glut" command in the program.
CrazyCrinkle, I think... you should probably go back to some basics.

Specifically, the issue in this case is that you're using things you don't really understand for reasons you don't understand. That's not a good thing. You'll only confuse yourself further.
You're right im not understanding them, but thats the point. Get things working and then start to play around with it and learn how it works by messing with it. Thats how I learn best!
> (sorry its an image but you cant copy and paste from the build log)
Right click -> copy contents to clipboard
Also, what you posted is not the build log. The title says "Build messages"

> My build command is F9
Look at the "Build log", you'll find something like
g++ -Wall -g -c foo.cpp -o foo.o



> then I get "undefined reference" on basically every "_glut" command in the program.
http://www.cplusplus.com/forum/general/113904/
You did not linked against glut
Project -> Build options -> Linker settings -> Add -> glut
That would add a -lglut flag to the build command
(may also need to add GL and GLEW)


> A) where to download glew
> B) Step-by-step, how to install which bits where.
Use the official repositories and your package manager
By instance
# pacman --Sync glew
Last edited on
Topic archived. No new replies allowed.