473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Design question

Hi,

I have a small question about design, implemented in C++ of course ;)

I have a set of objects A, B and C, which are pure C++ code (no GUI,
I/O, ...). I need to draw them on screen (using OpenGL), but i don't
want to put my OpenGL methods in my class A, B and C.

How can i do that ? Using an aggregate object member of my class, using
derivation, ... ?

Thanks.

Jan 31 '06 #1
9 1609

everg...@gmail.com escreveu:
Hi,

I have a small question about design, implemented in C++ of course ;)

I have a set of objects A, B and C, which are pure C++ code (no GUI,
I/O, ...). I need to draw them on screen (using OpenGL), but i don't
want to put my OpenGL methods in my class A, B and C.

How can i do that ? Using an aggregate object member of my class, using
derivation, ... ?

Thanks.


In order to isolate your logic from the specifics of OpenGL I would
create a layer (drawing layer) of classes that would know how to draw
your objects and would let a controller class coordinate the drawing
passing to the drawing layer the objects to be drawn.

HTH,

Marcelo Pinto

Jan 31 '06 #2

<ev******@gmail.com> schrieb im Newsbeitrag
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

I have a small question about design, implemented in C++ of course
;)

I have a set of objects A, B and C, which are pure C++ code (no GUI,
I/O, ...). I need to draw them on screen (using OpenGL), but i don't
want to put my OpenGL methods in my class A, B and C.

How can i do that ? Using an aggregate object member of my class,
using
derivation, ... ?


class TRIANGLE
{
float xyz[3][3];
};

template <class CData> class GLDrawObject
{
virtual std::vector<TRIANGLE>* GetTriangles() = 0;
};

class A
{
std::vector<TRIANGLE>* GetTirangles()
{
yaddayadda;
}
};

Just my .02$

Jan 31 '06 #3
Thanks, but i want to avoid a big switch case with all my object types
in this layer. This is what you mean ?

Jan 31 '06 #4

ev******@gmail.com escreveu:
Thanks, but i want to avoid a big switch case with all my object types
in this layer. This is what you mean ?


No it is not. If you fall in that situation you could use some factory
and some hierarchy on the OpenGL side or you could use templates to
parameterize the processing. But without seeing some code it is
dificult to understand the exact problem you are facing.

HTH,

Marcelo Pinto

Jan 31 '06 #5
I am on the design phase, no code for the moment ;-)

Jan 31 '06 #6
<ev******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

I have a small question about design, implemented in C++ of course ;)

I have a set of objects A, B and C, which are pure C++ code (no GUI,
I/O, ...). I need to draw them on screen (using OpenGL), but i don't
want to put my OpenGL methods in my class A, B and C.

How can i do that ? Using an aggregate object member of my class, using
derivation, ... ?

Thanks.


Consider deriving from a base that does the openGL calls for you. If at
some point you switch to, for instance, DirectX you would only have to
change the base class. In theory.
Jan 31 '06 #7
On 31 Jan 2006 05:49:29 -0800, ev******@gmail.com wrote:
I have a set of objects A, B and C, which are pure C++ code (no GUI,
I/O, ...). I need to draw them on screen (using OpenGL), but i don't
want to put my OpenGL methods in my class A, B and C.


Some good suggestions here. You might also consider the newsgroups
below as they are populated with people who solve OpenGL problems
on a daily basis.

comp.graphics.algorithms
comp.graphics.api.opengl

What I did was basically wrap various OpenGL functions and sequences
of functions into a few "stand alone" classes. I then called these
from my GUI classes. I had reduced what could have been many calls to
OpenGL "all over the place" to a few simple calls to the OpenGL
classes. To pull those out and replace them with DX calls should be
easy if it ever happens. (Which it won't as long as I breath. :-) ).

A downside to this was I had created a tight coupling between my gui
classes and the OpenGL classes. This was by design though. I created
the whole "thing" to be a subsystem along the lines of the Facade
pattern.

HTH
Jan 31 '06 #8

<ev******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

I have a small question about design, implemented in C++ of course ;)

I have a set of objects A, B and C, which are pure C++ code (no GUI,
I/O, ...). I need to draw them on screen (using OpenGL), but i don't
want to put my OpenGL methods in my class A, B and C.

How can i do that ? Using an aggregate object member of my class, using
derivation, ... ?

Thanks.


I've solved this type of graphics problem a number of times by using a
Visitor Pattern in conjunction with the Composite Pattern. The visitor
derived object then can take care of the particular graphics system outside
of the classes A, B, or C.

Feb 5 '06 #9
I will have a look to those patterns, thanks ;)

Feb 6 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
2
by: Test User | last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people as possible) I am somewhat familiar with Access 2000, but my latest project has me stumped. So, I defer to you...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
8
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.