Windows OpenGl problem(Code::Blocks)

I'm currently trying to learn OpenGl, and my book uses windows along side openGL. The problem though is that i keep getting errors that i do not understand what so ever. Could someone PLEASE help me out! at the moment im just creating the project using a console application, i dont know what to do!
Errors
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
||=== Why, Debug ===|
obj\Debug\main.o||In function `Z14MainWindowProcP6HWND__jjl@16':|
F:\OpenGl\Why\main.cpp|62|undefined reference to `wglCreateContext@4'|
F:\OpenGl\Why\main.cpp|63|undefined reference to `wglMakeCurrent@8'|
F:\OpenGl\Why\main.cpp|71|undefined reference to `wglMakeCurrent@8'|
F:\OpenGl\Why\main.cpp|72|undefined reference to `wglDeleteContext@4'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|24|undefined reference to `glClearColor@16'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|43|undefined reference to `glViewport@16'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|44|undefined reference to `glMatrixMode@4'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|45|undefined reference to `glLoadIdentity@0'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|48|undefined reference to `gluPerspective@32'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|50|undefined reference to `glMatrixMode@4'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|51|undefined reference to `glLoadIdentity@0'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|65|undefined reference to `glClear@4'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|66|undefined reference to `glLoadIdentity@0'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|69|undefined reference to `glTranslatef@12'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|70|undefined reference to `glRotatef@16'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|71|undefined reference to `glRotatef@16'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|72|undefined reference to `glRotatef@16'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|75|undefined reference to `glColor3f@12'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|78|undefined reference to `glBegin@4'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|79|undefined reference to `glVertex3f@12'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|80|undefined reference to `glVertex3f@12'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|81|undefined reference to `glVertex3f@12'|
obj\Debug\CGfxOpenGL.o:F:\OpenGl\Why\CGfxOpenGL.cpp|82|undefined reference to `glEnd@0'|
||=== Build finished: 23 errors, 0 warnings ===|


Last edited on
Main.cpp up to line 82
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
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HDC hDC;
    static HGLRC hRC;
    int height, width;

    // dispatch messages
    switch (uMsg)
    {
    case WM_CREATE:         // window creation
        hDC = GetDC(hWnd);
        SetupPixelFormat(hDC);
        //SetupPalette();
        hRC = wglCreateContext(hDC);
        wglMakeCurrent(hDC, hRC);
        break;

    case WM_DESTROY:            // window destroy
    case WM_QUIT:
    case WM_CLOSE:                  // windows is closing

        // deselect rendering context and delete it
        wglMakeCurrent(hDC, NULL);
        wglDeleteContext(hRC);

        // send WM_QUIT to message queue
        PostQuitMessage(0);
        break;

    case WM_SIZE:
        height = HIWORD(lParam);        // retrieve width and height
        width = LOWORD(lParam);
//....rest of program 
Last edited on
CGfOpenGL.h
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
#ifndef __GL_COMPONENT
#define __GL_COMPONENT

#define PI 3.14159
#define TWO_PI PI*2.0
#define HALF_PI PI/2.0

class CGfxOpenGL
{
private:
	int m_windowWidth;
	int m_windowHeight;

	float m_angle;

public:
	CGfxOpenGL();
	virtual ~CGfxOpenGL();

	bool Init();
	bool Shutdown();

	void SetupProjection(int width, int height);

	void Prepare(float dt);
	void Render();
};

#endif 




CGfxOpenGl.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifdef _WINDOWS
#include <windows.h>
#endif

#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>
#include "CGfxOpenGL.h"

// disable implicit float-double casting
#pragma warning(disable:4305)

CGfxOpenGL::CGfxOpenGL()
{
}

CGfxOpenGL::~CGfxOpenGL()
{
}

bool CGfxOpenGL::Init()
{   
    // clear to black background
    glClearColor(0.0, 0.0, 0.0, 0.0);

    m_angle = 0.0f;

    return true;
}

bool CGfxOpenGL::Shutdown()
{
    return true;
}

void CGfxOpenGL::SetupProjection(int width, int height)
{
    if (height == 0)                    // don't want a divide by zero
    {
        height = 1;                 
    }

    glViewport(0, 0, width, height);        // reset the viewport to new dimensions
    glMatrixMode(GL_PROJECTION);            // set projection matrix current matrix
    glLoadIdentity();                       // reset projection matrix

    // calculate aspect ratio of window
    gluPerspective(52.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);

    glMatrixMode(GL_MODELVIEW);             // set modelview matrix
    glLoadIdentity();                       // reset modelview matrix

    m_windowWidth = width;
    m_windowHeight = height;
}

void CGfxOpenGL::Prepare(float dt)
{
    m_angle += 0.1f;
}

void CGfxOpenGL::Render()
{
    // clear screen and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     
    glLoadIdentity();

    // move back 5 units and rotate about all 3 axes
    glTranslatef(0.0, 0.0, -5.0f);
    glRotatef(m_angle, 1.0f, 0.0f, 0.0f);
    glRotatef(m_angle, 0.0f, 1.0f, 0.0f);
    glRotatef(m_angle, 0.0f, 0.0f, 1.0f);

    // lime greenish color
    glColor3f(0.7f, 1.0f, 0.3f);

    // draw the triangle such that the rotation point is in the center
    glBegin(GL_TRIANGLES);
        glVertex3f(1.0f, -1.0f, 0.0f);
        glVertex3f(-1.0f, -1.0f, 0.0f);
        glVertex3f(0.0f, 1.0f, 0.0f);
    glEnd();
}
You need to tell the compiler where the OpenGL libraries are...

Try putting these at the top of CGfxOpenGl.cpp (change PATH TO to the directory in which the files are located)
#pragma comment(lib, "PATH TO\gl.lib")
#pragma comment(lib, "PATH TO\glu.lib")
Last edited on
The OP is using GNU linker, not Visual Studio ... The libraries are named libopengl32.a, libglu.a, libgl.a (don't remember correctly the names) and must be set in IDE settings or command line, #pragma directive does not work.
Topic archived. No new replies allowed.