Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4266186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:43:34+00:00 2026-05-21T06:43:34+00:00

System Specs and task I am using Code::Blocks on Ubuntu 10.10 and playing around

  • 0

System Specs and task

I am using Code::Blocks on Ubuntu 10.10 and playing around with OpenGL and glx. I’m in the process of learning C++(from a background in C and Java), so the style of any code doesn’t conform to any real good standards (but I’m open to suggestions on how to improve, even if you don’t have an answer to the question)

Edit:

Huge Realization: The default OpenGL Project Code::Blocks creates is C, not C++. I’m looking into this now.

I’m currently trying to modify the default OpenGL project on Code::Blocks into a simple 3d engine. I am currently getting the error:

expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Draw’

Which disappears as soon as I comment out the #include for < GL/glx.h>

I read on a forum somewhere that Code::Blocks doesn’t look in usr/include/ by default, but I added that to the search directories for the compiler in the project build options and it didn’t seem to fix anything.

Code:

main.cpp: main.c:

#include <time.h>
#include "Draw.h"

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{

/*draw init here*/

Draw::Draw renderer = Draw::Draw.getDraw();

printf( "Press left mouse button to rotate around X axis\n" );
printf( "Press middle mouse button to rotate around Y axis\n" );
printf( "Press right mouse button to rotate around Z axis\n" );
printf( "Press ESC to quit the application\n" );

/* timing variable*/
/* Set it to delay half a second before rendering the first frame*/
clock_t flip_time = clock() + 0.5f * CLOCKS_PER_SEC;

while (1)
{


    /* Update models */


    /* Draw scene */

    /*  wait until it's been 1/60th of a second*/
    while(clock() < flip_time){}

    flip_time = clock() + (1.0f/60.0f) * CLOCKS_PER_SEC;
    /* Actually flip the frame */

}
}

Draw.h:

#ifndef DRAW_H
#define DRAW_H

#include <GL/glx.h>    /* This is the problem line */
#include <GL/gl.h>

#include <X11/X.h>    /* X11 constant (e.g. TrueColor) */
#include <X11/keysym.h>

class Draw
{
public:
    static Draw getDraw();
    virtual ~Draw();
    void update();
    void render();

protected:
private:
    Draw();
    bool init();

    /* The singleton*/
    static Draw *instance;
    static bool exists;

    /* X Window values */
    Display             *dpy;
    Window               win;
    GLboolean            doubleBuffer;

    /* X Parameters*/
    XVisualInfo         *vi;
    Colormap             cmap;
    XSetWindowAttributes swa;
    GLXContext           cx;
    XEvent               event;
    int                  dummy;

};

#endif // DRAW_H

Last, but not least Draw.cpp:

#include "Draw.h"

/* Set up the singleton*/
bool Draw::exists = false;
Draw* Draw::instance = NULL;

Draw::Draw()
{
/*TODO: make this constructor */
}

Draw::~Draw()
{
//dtor
}

Draw Draw::getDraw()
{
if(!exists)
{
    instance = new Draw();
    instance->init();
    exists = true; //Thanks mat, This line was accidentally removed with extraneous comments
}

return *instance;
}

bool Draw::init()
{
/* Get the buffers ready */
static int snglBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, None};
static int dblBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};

/* Double Buffered is best*/
doubleBuffer = GL_TRUE;

/*TODO: add constructor if it hasn't been constructed already*/

dpy = XOpenDisplay(NULL);
if (dpy == NULL)
{
    return false;
}

/* make sure OpenGL's GLX extension supported */
if(!glXQueryExtension(dpy, &dummy, &dummy))
{
    return false;
}

/* find an appropriate visual */
/* find an OpenGL-capable RGB visual with depth buffer */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf);

if (vi == NULL)
{
    vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf);
    if (vi == NULL)
    {
        return false;
    }

    doubleBuffer = GL_FALSE;
}


/*
TODO: Fix or remove this
if(vi->class != TrueColor)
{
    return false;
}
*/
/* create an OpenGL rendering context  */

/* create an OpenGL rendering context */
cx = glXCreateContext(dpy, vi, /* no shared dlists */ None,
                    /* direct rendering if possible */ GL_TRUE);
if (cx == NULL)
{
    return false;
}

/* create an X window with the selected visual */

/* create an X colormap since probably not using default visual */
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = KeyPressMask    | ExposureMask
             | ButtonPressMask | StructureNotifyMask;
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0,
                  300, 300, 0, vi->depth, InputOutput, vi->visual,
                  CWBorderPixel | CWColormap | CWEventMask, &swa);
XSetStandardProperties(dpy, win, "main", "main", None,
                     NULL, NULL, NULL);

/* bind the rendering context to the window */
glXMakeCurrent(dpy, win, cx);

/* request the X window to be displayed on the screen */
XMapWindow(dpy, win);

/* configure the OpenGL context for rendering  */
glEnable(GL_DEPTH_TEST); /* enable depth buffering */
glDepthFunc(GL_LESS);    /* pedantic, GL_LESS is the default */
glClearDepth(1.0);       /* pedantic, 1.0 is the default */

/* frame buffer clears should be to black */
glClearColor(0.0, 0.0, 0.0, 0.0);

/* set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
/* establish initial viewport */

/* pedantic, full window size is default viewport */
glViewport(0, 0, 300, 300);

return true;
}

void Draw::update()
{
/*TODO: Add things to draw here*/
}

void Draw::render()
{
    /* actually flip buffers here */
}

I removed a ton of comments before posting this here, but that shouldn’t affect whether or not it compiles.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:43:34+00:00Added an answer on May 21, 2026 at 6:43 am

    I found the issue with the linking.

    The default project for OpenGL in Code::Blocks is NOT C++, it’s C. I configured it to use g++ and it fixed the issue with glx not linking in correctly. I revised my singleton to look a little more like this and it works correctly now too. I have an issue now with the window not appearing, but I should be able to figure that out.

    Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

System Specs: Infopath 2007 with c# code-behind Webservices Active Directory I need to get
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GenericCount { class Program {
For some part of my project I need a process-local scheduling system that will
I'm completely lost on this one: System.getProperty(user.home) and System.getProperty(user.name) returns a questionmark ?. System-Specs:
We recently bought two new build machines that have the same specs/hardware. From what
System.IO.Directory.GetFiles() returns a string[] . What is the default sort order for the returned
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to
System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml
The system I am currently working on requires some role-based security, which is well
Are System.IO.Compression.GZipStream or System.IO.Compression.Deflate compatible with zlib compression?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.