Author Topic: [C++] attempt at opengl using C++.  (Read 5498 times)

0 Members and 1 Guest are viewing this topic.

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
[C++] attempt at opengl using C++.
« on: February 21, 2010 »
hi i just got a new coursework assignment and i thought it would be a good idea to set up a basic framework to build opengl programs before actualy starting on the prodject as a whole.

anywho as this is my first attempt at a C++ program that performs any sort of meaningful task i was wondering if someone that knows a little more about C++ could give it a look over and cheack if the C++ is OK.

cheers,
james
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline Praecor

  • Atari ST
  • ***
  • Posts: 176
  • Karma: 13
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #1 on: February 21, 2010 »
maybe aim for simplicity, make a console prj, initialize gl with four and half lines of code (rendering context, pixelformat, popupwnd) + enter into the frame loop, clear screen, render and swap the frontbuffer, reploop it doesn't require c++ or some fancy+flashy stuff

ie. 95% of the cases ppl use their time playing around with the unnecessarities (is my variable naming right etc) and they forget that the world only cares what they can see on their screen(the end app), the hard part is anyway the actual product which should be 95% of your priority (which has nothing to do how you represent it in the code)
Challenge Trophies Won:

Offline Praecor

  • Atari ST
  • ***
  • Posts: 176
  • Karma: 13
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #2 on: February 21, 2010 »
Another alternative often employed today, is to try to code not at all, if possible. It's done by downloading n+1 libraries off the net and calling libs Load(), Update(), Draw() and Release() methods.

This is what i do for work. Misses the fun part though.
Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #3 on: February 21, 2010 »
hi
cheers for the advice i see what you meen about simplicity the project as it is does look a little wordy considering what it does. the idea to begin with was to re-write a system i already had working in C# in C++ (we're not allowed to use c# in most of our projects this year) so i could quickly get on with the project (as i can already do the opengl side of things) but i think it got a little complicated in the translation.

at the moment i'm torn between sticking with it because it works and i need to get on or going back to basics to simplify it idealy i would like to simplify it but i'm not sure if i'll have the time.

thanks for the input

james
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [C++] attempt at opengl using C++.
« Reply #4 on: February 21, 2010 »
In my understanding of a proper class-hierarchy, a class called "StartState" shouldn't render a teapot.

Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #5 on: February 21, 2010 »
 ah the teapot was just there to check that the display method is was working proerly whilst i was testing i thought i removed it i have changed it since so that it displays the initial state of the program sorry about that

james
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [C++] attempt at opengl using C++.
« Reply #6 on: February 22, 2010 »
Your class-layout looks like you tried to separate view and data.
That's usually a good approach to keep things modular and reusable.
But in that case your data shouldn't do the rendering.
Have a look at the MVC pattern.
Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #7 on: February 22, 2010 »
ah i see so at the moment my state renders things but what should be done is that the model holds all the data (ie positions etc) and the view takes that data and renders the screen and the controller(as it is the controller and view are joint) should handle user input is that right?

james   
« Last Edit: February 22, 2010 by James_wright_1990 »
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline nawitus

  • C= 64
  • **
  • Posts: 50
  • Karma: 1
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #8 on: February 27, 2010 »
I'm not actually sure what the question is, but I simply used SDL and OpenGL. SDL provides some input functions and other helping stuff.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #9 on: February 28, 2010 »
James, I think Hellfire is hinting that instead of your T implementing its own rendering functions you could have an IRender<T> interface and classes that know how to render T.  This is desirable if you follow the anaemic data model which has model objects being exactly the data/Properties they represent, with no methods on them, and having other classes (factories) to create them, and services to manipulate them (in this case to draw them).  I'm pretty sure it was me that led you to have T (inheriting from an abstract class) which all implement a draw() method, but there are other ways :D

PS. I haven't read your code at all, yet.

Jim
« Last Edit: February 28, 2010 by Jim »
Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
Re: [C++] attempt at opengl using C++.
« Reply #10 on: March 01, 2010 »
hi
I think this is the way i am heading at the moment i currently have classes for geometric objects wich just have just data like size, location etc and two interfaces an IUpdate and an IDraw which tie to classes thast know how to draw and mainipulate the data depending on  what state the program is in.

james
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.