Advantage of C in computer graphics?

This is a discussion on Advantage of C in computer graphics? within the C Programming forums, part of the General Programming Boards category; Hi everyone! I was just wondering what would be an advantage of C when used for graphics code? I'm about ...

  1. #1
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73

    Advantage of C in computer graphics?

    Hi everyone! I was just wondering what would be an advantage of C when used for graphics code? I'm about to take a computer graphics class but it seems that it would be wiser to use java over C, because of simplicity? I feel like C could optimize better because of use of threads(i don't know about java).

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You can do threads in Java as well, so don't worry about that.

    Think of it as a continuum, or spectrum. Pretty much any programming language lies somewhere along this line. On one end you have very complex programming languages that are more centered around how a computer works. On the other end, you have languages that are based around how people think.

    Obviously the languages that are based around how a computer works are simpler for the computer. They have less over-head, they're easier for the computer to understand, and because you're thinking in a certain way, they're probably designed for better performance.

    Other languages are based around the way people think. So for instance, in a "low-level" language, you might say, "move this data over here, add it with this number, call this routine, move the data back, start over with different data", etc... It's very methodical, and complex - but faster for the computer to process. In a higher-level language you can say, "I have an object, it's called a car. You drive it like this... You stop like this... You turn like this... It can have a color, a speed, a license number, a certain number of pssengers, etc..

    C is more like the first (but can still be easy to understand - it is by no means as complex as Assembly) Java is more like the second.

    C can be faster, but Java can be easier for you to understand. It's a trade-off decision you have to make on a case-by-case basis and based on your preference.

    My personal recommendation is that if you're just learning, Java might be easier for you, because it's more based around the way a person thinks. On the other hand, doing it in C will teach you a lot about the bare-bones of how it all works, but you might have a steep learning curve!

  3. #3
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73
    i've taken C and Java, but what i know is still very little, chances are i'll probably mess up making an array of structs or end up having a memory leak like my last project i'm thinking structs in C vs objects in java. i might need a refresher... thank u for the input!! by the way is there an openGL library for C and for java? if so, what are they, and which is cleaner (to use) than the other?
    Last edited by NoobieGecko; 08-27-2008 at 10:58 PM.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Java is "safer" as far as memory leaks go. But then again - badly designed code is badly designed code - it doesn't matter a whole lot what language you speak!

    It sounds like you'd probably enjoy Java more. Which one you would get more out of is up to you, but have a look on Google - there's a million resources for OpenGL.

    And wikipedia might be a good place to start:

    http://en.wikipedia.org/wiki/OpenGL

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    It depends on the kind of graphics code somewhat. If you want to make a game, I think C++ would be your best choice. If its just an application that doesn't need that much speed, I think java would be ok. I don't think C would be very good for games however, but it is possible and it will most likely be the fastest.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by lruc View Post
    I don't think C would be very good for games however, but it is possible and it will most likely be the fastest.
    This is the typical "C is faster than C++" argument. And whilst it's quite likely that an old C compiler produced better code than the same generation C++ compiler, modern C++ compilers are darn good. So as long as the programmer understands what he/she is doing, then the code from a C++ solution or a C solution should be pretty close. Of course, if you use for example a std::vector C++ to solve a problem that C uses a statically sized array, then there may be a difference - this is a consequence of "You can have freedom or speed - but not both" - so if you want dynamic arrays, then the result would be pretty similar in C and C++ - and if you don't, then don't use dynamic arrays in the C++ solution.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    You are right. The difference between C and C++wouldn't even be close enough to notice. I didn't neccesarly mean C is faster than C++, just about every other language though.

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    A C in computer graphics has the advantage of being a passing grade, although average. Yes, in a long enough timeline, all replies will reduce to outright sarcasm.

  9. #9
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by NoobieGecko View Post
    Hi everyone! I was just wondering what would be an advantage of C when used for graphics code? I'm about to take a computer graphics class but it seems that it would be wiser to use java over C, because of simplicity? I feel like C could optimize better because of use of threads(i don't know about java).
    My job for 9 years was low-level raster graphics development. From that standpoint I can say, C vs. C++ is pretty much irrelevant with respect to raw graphics development. The fundamental operation is the manipulation of a pixel. The key to well-performing graphics is the use of a low level language, at least as far as pixel manipulation is concerned.

    So to really answer your question, which seems to ask whether higher or lower-level languages are preferred for graphics, depends on how abstractly you are manipulating the graphics. For low-level manipulation, you obviously would prefer a lower-level language like C or C++. If you are taking advantage of a performance API like DirectX or OpenGL, then the specific choice of language is less important, and you would probably make your decision based on higher level architectural concerns.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 05:06 PM
  2. Problems shutting off computer
    By frenchfry164 in forum Tech Board
    Replies: 9
    Last Post: 04-22-2003, 06:19 PM
  3. Which distro should I run on my old computer?
    By joshdick in forum Tech Board
    Replies: 5
    Last Post: 04-09-2003, 01:37 AM
  4. Computer engineering - programming.
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 07-15-2002, 02:37 PM
  5. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21