I need to get working gtk3 with vtk6.
Ive just built (after some effort) gtkglext for gtk3.
Later I built vtkmm1.2 with the win32 patches and I do not see vtk widget.
Due to this, I discovered I cant see any draw in the gtkglext examples.
On the other side, Ive tried the excellent example of gtkglarea (the new, gtk built in one ) with plain opengl from https://www.bassi.io/articles/2015/02/17/using-opengl-with-gtk/
and I get no draw because "fb setup not supported".
It seems the framebuffer is complete, checking gtkglarea.c.
How can i solve this?
Anyone have been able to draw something in gtk with opengl, for windows?
This is the simplest code i've made,and i'm getting the mentioned error enter image description here, and adapting the signals to the new built in GtkGLArea ("render" instead of "draw")
#include <math.h>
#include <gtk/gtk.h>
//#include <gtkgl/gtkglarea.h> //LUCIANO, gtkglarea is built in now
#include <gtk/gtkglarea.h>
#include <GL/gl.h>
gint init(GtkWidget *widget)
{
/* OpenGL functions can be called only if make_current returns true */
gtk_gl_area_make_current(GTK_GL_AREA(widget));
{
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
glViewport(0, 0, allocation.width, allocation.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,100, 100,0, -1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
return TRUE;
}
/* When widget is exposed it's contents are redrawn. */
gboolean draw (GtkWidget *widget, cairo_t *cr, gpointer data)
{
/* OpenGL functions can be called only if make_current returns true */
gtk_gl_area_make_current(GTK_GL_AREA(widget));
{
/* Draw simple triangle */
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,1);
glBegin(GL_TRIANGLES);
glVertex2f(10,10);
glVertex2f(10,90);
glVertex2f(90,90);
glEnd();
/* Swap backbuffer to front */
//ggla_area_swap_buffers(GGLA_AREA(widget));
gtk_gl_area_attach_buffers(GTK_GL_AREA(widget));
}
return TRUE;
}
/* When glarea widget size changes, viewport size is set to match the new size */
gint reshape(GtkWidget *widget, GdkEventConfigure *event)
{
/* OpenGL functions can be called only if make_current returns true */
//if (ggla_area_make_current(GTK_GL_AREA(widget)))
gtk_gl_area_make_current(GTK_GL_AREA(widget));
{
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
glViewport(0, 0, allocation.width, allocation.height);
}
return TRUE;
}
int main(int argc, char **argv)
{
GtkWidget *window,*glarea;
gchar *info_str;
/* Attribute list for gtkglarea widget. Specifies a
list of Boolean attributes and enum/integer
attribute/value pairs. The last attribute must be
GGLA_NONE. See glXChooseVisual manpage for further
explanation.
*/
int attrlist[] = {
// GGLA_RGBA,
// GGLA_RED_SIZE,1,
// GGLA_GREEN_SIZE,1,
// GGLA_BLUE_SIZE,1,
// GGLA_DOUBLEBUFFER,
// GGLA_NONE
};
/* initialize gtk */
gtk_init(&argc, &argv);
/* Check if OpenGL is supported. */
// if (ggla_query() == FALSE) {
// g_print("OpenGL not supported\n");
// return 0;
// }
/* Create new top level window. */
window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Simple");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
/* Quit form main if got delete event */
g_signal_connect(G_OBJECT(window), "delete-event",
G_CALLBACK(gtk_main_quit), NULL);
/* Create new OpenGL widget. */
//glarea = GTK_WIDGET(gtk_gl_area_new(attrlist));
glarea = gtk_gl_area_new();
/* Events for widget must be set before X Window is created */
gtk_widget_set_events(GTK_WIDGET(glarea),
GDK_EXPOSURE_MASK|
GDK_BUTTON_PRESS_MASK);
init(glarea);
/* Connect signal handlers */
/* Redraw image when exposed. */
// g_signal_connect(G_OBJECT(glarea), "draw",
// G_CALLBACK(draw), NULL);
// /* When window is resized viewport needs to be resized also. */
// g_signal_connect(G_OBJECT(glarea), "configure-event",
// G_CALLBACK(reshape), NULL);
// /* Do initialization when widget has been realized. */
// g_signal_connect(G_OBJECT(glarea), "realize",
// G_CALLBACK(init), NULL);
g_signal_connect(G_OBJECT(glarea), "render",
G_CALLBACK(draw), NULL);
/* When window is resized viewport needs to be resized also. */
// g_signal_connect(G_OBJECT(glarea), "resize",
// G_CALLBACK(reshape), NULL);
/* Do initialization when widget has been realized. */
// g_signal_connect(G_OBJECT(glarea), "create-context",
// G_CALLBACK(init), NULL);
/* set minimum size */
gtk_widget_set_size_request(GTK_WIDGET(glarea), 100,100);
/* put glarea into window and show it all */
gtk_container_add(GTK_CONTAINER(window),GTK_WIDGET(glarea));
gtk_widget_show(GTK_WIDGET(glarea));
gtk_widget_show(GTK_WIDGET(window));
/* vendor dependent version info string */
// info_str = ggla_get_info();
// g_print(info_str);
// g_free(info_str);
gtk_main();
return 0;
}
Related
I'm trying to run the example GLFW program on WSL2 with vcxsrv as the X server. There are no problems running the current program with the two lines commented out. When I uncomment only glCear(CL_COLOR_BUFFER_BIT);, it lags a bit when I drag the window around. When I uncomment only glfwSwapBuffers(window) the program crashes as soon as the window pops up, where dragging the window around becomes very laggy, and I am unable to close the window without terminating the app through the terminal. Why is this happening? Is there any way to improve the speed of these programs on WSL2?
Program:
#include <iostream>
#include <GLFW/glfw3.h>
static void glfwError(int /*id*/, const char* description)
{
std::cerr << description << '\n';
}
int main(void)
{
GLFWwindow* window;
glfwSetErrorCallback(&glfwError);
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
// glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
// glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
I am new to the ImGui library and recently i've been trying out the examples included. Everything worked like a charm until I changed the include (and functions) of gl3w to glad (the loader i would like to use). The moment I swapped between the two loaders I got a segmentation fault exception inside the imgui_impl_glfw_gl3.cpp file. I found a post which suggested that this may happen because of some functions failing to "bind" and producing nullpointers.
I have located the error in line 216 of imgui_impl_glfw_gl3.cpp
this is the code in line 216:
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
I have also changed the include file in imgui_impl_glfw_gl3.cpp from gl3w to glad with no results.
This is the main function i am executing (it's the basic opengl3 example of imgui using glad):
#include "gui/imgui.h"
#include "gui/imgui_impl_glfw_gl3.h"
#include <stdio.h>
#include <glad/glad.h> // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you.
#include <GLFW/glfw3.h>
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error %d: %s\n", error, description);
}
int main(int, char**)
{
// Setup window
glfwSetErrorCallback(error_callback);
if (!glfwInit())
return 1;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
glfwInit();
// Setup ImGui binding
ImGui_ImplGlfwGL3_Init(window, true);
// Setup style
//ImGui::StyleColorsDark();
ImGui::StyleColorsClassic();
bool show_demo_window = true;
bool show_another_window = false;
bool algo = true;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
ImGui_ImplGlfwGL3_NewFrame();
// 1. Show a simple window.
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
{
static float f = 0.0f;
static int counter = 0;
ImGui::Text("Hello, world!"); // Display some text (you can use a format string too)
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("COLORINES", (float*)&clear_color); // Edit 3 floats representing a color
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our windows open/close state
ImGui::Checkbox("Booleanooooo", &algo);
ImGui::Checkbox("Another Window", &show_another_window);
if (ImGui::Button("Button")) // Buttons return true when clicked (NB: most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("pues se ve que hay texto: %d", algo);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
}
{
ImGui::Begin("VENTANA WAPA");
ImGui::Text("POS SA QUEDAO BUENA VENTANA");
static float yee = 0.0f;
ImGui::SliderFloat("lel", &yee,1.0f,0.5f);
ImGui::End();
}
// 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window);
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}
// 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui!
if (show_demo_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
ImGui::ShowDemoWindow(&show_demo_window);
}
// Rendering
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
glfwSwapBuffers(window);
}
// Cleanup
//ImGui_ImplGlfwGL3_Shutdown();
glfwTerminate();
return 0;
}
I have no clue why this is happenning and I'm pretty new to openGL an ImGui so, any ideas? :(
Glad & gl3w are both extension loader libraries. They generally need to be initialized on a current GL context before use.
The original code called gl3wInit(). Yours is missing any sort of glad init.
Make sure you initialize glad (gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) after glfwMakeContextCurrent() and before you call any OpenGL functions.
Otherwise all the OpenGL function pointers glad declares will remain NULL. Trying to call NULL function pointers generally doesn't go well for a process.
I'm really new with GTK, and im trying to learn how to handle it for a project i have in mind.
The thing is, i could manage to make an app for placing "Generators" on a window ... Each time i click on the screen, the app place a gen in the window, and prepare another one ready to be placed ...
The problem is that the program blinks when is drawing all the generators ...
Each gen has to redraw itself all the time, and this is i think the problem... Here is the code ... how can i make it faster? ... Thanks in advance!!
// gcc main.c -o main `pkg-config gtk+-3.0 --cflags --libs`
#include <gtk/gtk.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
class Gen{
public:
int x;
int y;
GdkPixbuf *pix;
GtkWidget *canvas;
bool placed;
Gen(GtkWidget *canvas){
this->canvas=canvas;
GError *err = NULL;
pix = gdk_pixbuf_new_from_file("./Img/gen.png", &err);
pix= gdk_pixbuf_scale_simple(pix,50,50, GDK_INTERP_BILINEAR);
x=10;y=10;
placed=0;
}
void draw(cairo_t *cr){
gdk_cairo_set_source_pixbuf(cr, pix, x, y);
cairo_paint(cr);
}
void updatePosition(int a, int b){
if(placed==0){
x=a-25;
y=b-25;
}
}
void place(){
placed=1;
}
};
class Map{
public:
vector<Gen *> Gens;
GtkWidget *window;
GtkWidget *canvas;
int xPointer,yPointer;
Map(GtkWidget *_window, GtkWidget *_canvas){
window=_window;
canvas=_canvas;
}
void draw(){
cairo_t *cr;
cr = gdk_cairo_create (gtk_widget_get_window(canvas));
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_rectangle(cr, xPointer-35, yPointer-35, 70, 70);
cairo_paint(cr);
for(vector<Gen *>::const_iterator i=Gens.begin();i!=Gens.end();i++){
(*i)->draw(cr);
}
cairo_destroy (cr);
}
void place(){
Gen *aux=Gens.back();
aux->place();
//Gens.push_back(new Gen(canvas));
}
void moving(int x,int y){
xPointer=x;yPointer=y;
if(Gens.size()==0){
Gens.push_back(new Gen(canvas));
}
else if (Gens.back()->placed==1){
Gens.push_back(new Gen(canvas));
}
Gen *aux=Gens.back();
aux->updatePosition(x,y);
this->draw();
cout<<"Elementos -> "<<Gens.size()<<"\n";
}
};
static gboolean
moving(GtkWidget *da, GdkEvent *event, gpointer data)
{
int x, y;
GdkModifierType state;
gdk_window_get_device_position (gdk_event_get_window ((GdkEvent *) event),
gdk_event_get_device ((GdkEvent *) event),
&x, &y, &state);
/*
(void)event; (void)data;
((Gen *)da)->draw();*/
Map *g=(Map *)data;
g->moving(x,y);
}
static gboolean
placing (GtkWidget *da, GdkEvent *event, gpointer data)
{
Map *g=(Map *)data;
g->place();
}
int main ( int argc, char **argv) {
GtkWidget *window;
GtkWidget *canvas;
gtk_init (&argc , &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (window,
500, 500);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit) , NULL);
canvas = gtk_drawing_area_new ();
Map *g=new Map(window,canvas);
gtk_container_add (GTK_CONTAINER (window), canvas);
gtk_widget_set_events(window, GDK_POINTER_MOTION_MASK);
//g_signal_connect (canvas, "draw", G_CALLBACK (drawing), (gpointer *)g);
g_signal_connect (window, "motion-notify-event", G_CALLBACK (moving), (gpointer *)g);
g_signal_connect (window, "button-press-event", G_CALLBACK (placing), (gpointer *)g);
//g_signal_connect (canvas, "motion-notify-event", (GCallback) on_window_draw, NULL);
gtk_widget_set_app_paintable(canvas, TRUE);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Several remarks here:
Gen::pix is allocated each time a Gen object is created. It's the same pixbuf, but you create one, then another one when using the scaling function (meaning you're leaking memory of the original pixbuf), and this for each Gen object. This is really unefficient, so using a static pix member, loading then scaling the pixbuf and fixing the memory leak would allow you to do this only once.
Then: you're calling gdk_cairo_create in the draw handler, but since GTK 3, you're supposed to get the cairo context as an input parameter in the draw signal callback. I see you're calling a custom draw method through the motion events, that's not how the GTK+ drawing stack works!
To do it right:
in the main, connect to the draw signal of the GtkDrawingArea
in your motion callbacks, just change positions of the Gen objects, and call gtk_widget_queue_draw for the drawing area. This will fire the draw signal for you.
in the callback connected to the draw signal, you then redraw your Gen objects in the cairo context you're given.
to improve performance, you can use the cairo clipping functions, or call gtk_widget_queue_draw_area or gtk_widget_queue_draw_region instead of gtk_widget_queue_draw. You'll get then a pre-computed clipping region in the cairo context you'll receive in your draw callback. With those hints, you can determine exactly what part of the image needs to be redrawn, and avoid unnecessary work.
Please read The GTK+ Drawing Model in the official documentation.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
Display *dis;
int screen;
Window win;
GC gc;
void init_x() {
/* get the colors black and white (see section for details) */
unsigned long black,white;
/* use the information from the environment variable DISPLAY
to create the X connection:
*/
dis=XOpenDisplay((char *)0);
screen=DefaultScreen(dis);
black=BlackPixel(dis,screen), /* get color black */
white=WhitePixel(dis, screen); /* get color white */
/* once the display is initialized, create the window.
This window will be have be 200 pixels across and 300 down.
It will have the foreground white and background black
*/
win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,
200, 300, 5, white, black);
/* here is where some properties of the window can be set.
The third and fourth items indicate the name which appears
at the top of the window and the name of the minimized window
respectively.
*/
XSetStandardProperties(dis,win,"My Window","HI!",None,NULL,0,NULL);
/* this routine determines which types of input are allowed in
the input. see the appropriate section for details...
*/
XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask);
/* create the Graphics Context */
gc=XCreateGC(dis, win, 0,0);
/* here is another routine to set the foreground and background
colors _currently_ in use in the window.
*/
XSetBackground(dis,gc,white);
XSetForeground(dis,gc,black);
/* clear the window and bring it on top of the other windows */
XClearWindow(dis, win);
XMapRaised(dis, win);
}
int main()
{
init_x();
return 0;
}
This is my first program to get started with X programming. I got this sample code from Internet, I compiled and ran the code but there is no output window.Can anyone please guide me what modification is required here to display a window.
You don't have an event loop, so the program initializes the window and then exits immediately.
Try using
XEvent e;
while (1) {
XNextEvent(dis, &e);
if (e.type == KeyPress)
break;
}
and also clean up on exit using
XCloseDisplay(dis);
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!
This line in your main file is wrong:
Draw::Draw renderer = Draw::Draw.getDraw();
Draw::Draw is not a type. To get this to compile, you just need:
Draw renderer = Draw.getDraw();
It looks like you're trying to build a singleton. You code does not do that at all, you'll get a copy each time. (Note that you're not setting exists anywhere, but that's just an extra bug.) You should be returning a pointer or a reference to the shared instance. See for instance this article to get the syntax right: C++ Singleton design pattern.
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!