Sign in to follow this  
CryoGenesis

C++ Graphics help.

Recommended Posts

Hey there, I've been programming in Java for 2 years and I've recently gotten hold of a NVidia GTX 660. I want to work on my own 3D rendering program but I have no idea how to draw 2D Images to the screen in C++. I know how to do it in Java but C++ looks a little bit more complicated when it comes to making windows. 

I'm using Ubuntu 12.10 64-bit and using NVidia's nvcc compiler which uses gcc and g++.

All I want to do is draw a 2D image to the screen. No GUI, no window borders, just an image.

One idea I had was to set up a socket connection between a C++ app and a Java app which sends the pixel data over my computer to the Java app which displays the image but I think that may be a bit slow (I have no idea).

Is there a way to do this without any external libraries? Can I do this with just the gcc and g++ includes?

Any help is appreciated and I'll give +1 rep for any helpful answers.

Share this post


Link to post
Share on other sites

C++ as a language has no concept of graphics so you'll have to use some sort of API/library to do your rendering/window setup. SDL is a popular choice, as is SFML and GLFW. Maybe elaborate on what you wish to achieve short and long term to get more accurate responses.

Share this post


Link to post
Share on other sites

Well, literally all I want to do is to draw a 2D image onto the screen from an array of pixels. The pixels will be manipulated from the C++ program. I want it to be fullscreen and I want it to update the image every time the program updates. So, no window borders or pretty GUI stuff, just a 2D image. Right now I'm going to try and write a java program that reads a 2D image from a file and displays it and at the same time the C++ program writes to the 2D image. The problem with that is thread problems and getting the image to be read when C++ has finished writing it,

Share this post


Link to post
Share on other sites
Hey there, I've been programming in Java for 2 years and I've recently gotten hold of a NVidia GTX 660. I want to work on my own 3D rendering program but I have no idea how to draw 2D Images to the screen in C++. I know how to do it in Java but C++ looks a little bit more complicated when it comes to making windows. 

I'm using Ubuntu 12.10 64-bit and using NVidia's nvcc compiler which uses gcc and g++.

All I want to do is draw a 2D image to the screen. No GUI, no window borders, just an image.

One idea I had was to set up a socket connection between a C++ app and a Java app which sends the pixel data over my computer to the Java app which displays the image but I think that may be a bit slow (I have no idea).

Is there a way to do this without any external libraries? Can I do this with just the gcc and g++ includes?

Any help is appreciated and I'll give +1 rep for any helpful answers.

 

Wait, do you want to work on a 3D rendering program, or just a 2D one where you directly set each pixel of an image and then just draw that to the screen?

 

I recommend you find some simple OpenGL tutorials online and then start playing around with setting up OGL and drawing some simple shapes to the screen.  Then you can texture them.  (at that point you can get a pointer to the texel data and do whatever you want with it).  Then move on to more advanced stuff like moving the camera around, etc.

 

http://www.swiftless.com/opengltuts.html

 

http://www.blitzbasic.com/Community/posts.php?topic=42662

Edited by 0r0d

Share this post


Link to post
Share on other sites

If you use a 2D library like SDL, your NVidia GTX 660 will be unused because all the rendering is done in software.

 

I suggest OpenGL (or DirectX if you dislike portability).

 

If you prefer to use a higher level library (like you would if using Java), then I suggest Irrlicht and the following tutorial in particular.

 

http://irrlicht.sourceforge.net/docu/example006.html

 

That should get you started pretty quickly and although the engine can do 3D, it does 2D well with the added benefit of being hardware accelerated.

Share this post


Link to post
Share on other sites
Hey there, I've been programming in Java for 2 years and I've recently gotten hold of a NVidia GTX 660. I want to work on my own 3D rendering program but I have no idea how to draw 2D Images to the screen in C++. I know how to do it in Java but C++ looks a little bit more complicated when it comes to making windows. 

I'm using Ubuntu 12.10 64-bit and using NVidia's nvcc compiler which uses gcc and g++.

All I want to do is draw a 2D image to the screen. No GUI, no window borders, just an image.

One idea I had was to set up a socket connection between a C++ app and a Java app which sends the pixel data over my computer to the Java app which displays the image but I think that may be a bit slow (I have no idea).

Is there a way to do this without any external libraries? Can I do this with just the gcc and g++ includes?

Any help is appreciated and I'll give +1 rep for any helpful answers.

 

Wait, do you want to work on a 3D rendering program, or just a 2D one where you directly set each pixel of an image and then just draw that to the screen?

 

I recommend you find some simple OpenGL tutorials online and then start playing around with setting up OGL and drawing some simple shapes to the screen.  Then you can texture them.  (at that point you can get a pointer to the texel data and do whatever you want with it).  Then move on to more advanced stuff like moving the camera around, etc.

 

http://www.swiftless.com/opengltuts.html

 

http://www.blitzbasic.com/Community/posts.php?topic=42662

 

I'm going to be writing my own rasteriser that converts a 3D world space into a 2D image that is drawn on the screen. I managed to do it in Java but I got a new graphics card which is CUDA enabled. It means I can do lots of parallel processing and make the program run a lot faster. Problem is that I don't know how to draw 2D images with C++ ;D

I was thinking about using OpenGL to draw the 2D image but I don't know how to create a window to set the OpenGL library to draw to. I'll look it up on teh googhels.

Share this post


Link to post
Share on other sites
If you use a 2D library like SDL, your NVidia GTX 660 will be unused because all the rendering is done in software.

 

I suggest OpenGL (or DirectX if you dislike portability).

 

If you prefer to use a higher level library (like you would if using Java), then I suggest Irrlicht and the following tutorial in particular.

 

http://irrlicht.sourceforge.net/docu/example006.html

 

That should get you started pretty quickly and although the engine can do 3D, it does 2D well with the added benefit of being hardware accelerated.

My GTX 660 is CUDA enabled. This allows me to use the CUDA SDK to program the graphics cards to do mathematical operations in C++. It's very useful because I can do around 800GHz of operations. If I used a 2D library like SDL the only function I would be using would be to draw an image, all the image manipulation and/or the rasterizer math would be done with cuda code. I think my GPU comes with 1000 cuda cores. It allows me to do program the 3D stuff from scratch whilst making it incredibly fast. Problem is, if I tried to use it with another computer it wouldn't run.

So, essentially, I'm going to be coding the hardware acceleration myself and use some random library to just draw the pixel array to the screen. 

Share this post


Link to post
Share on other sites
 

 

Wait, do you want to work on a 3D rendering program, or just a 2D one where you directly set each pixel of an image and then just draw that to the screen?

 

I recommend you find some simple OpenGL tutorials online and then start playing around with setting up OGL and drawing some simple shapes to the screen.  Then you can texture them.  (at that point you can get a pointer to the texel data and do whatever you want with it).  Then move on to more advanced stuff like moving the camera around, etc.

 

http://www.swiftless.com/opengltuts.html

 

http://www.blitzbasic.com/Community/posts.php?topic=42662

 

I'm going to be writing my own rasteriser that converts a 3D world space into a 2D image that is drawn on the screen. I managed to do it in Java but I got a new graphics card which is CUDA enabled. It means I can do lots of parallel processing and make the program run a lot faster. Problem is that I don't know how to draw 2D images with C++ ;D

I was thinking about using OpenGL to draw the 2D image but I don't know how to create a window to set the OpenGL library to draw to. I'll look it up on teh googhels.

 

Ok, so yeah, follow the links I gave.  You just need to set up OGL and draw a full-screen textured quad w/ a texture that you create in memory.  Then get the pointer to the texels and you can set them to whatever RGB values you want.

Share this post


Link to post
Share on other sites
 

 

Wait, do you want to work on a 3D rendering program, or just a 2D one where you directly set each pixel of an image and then just draw that to the screen?

 

I recommend you find some simple OpenGL tutorials online and then start playing around with setting up OGL and drawing some simple shapes to the screen.  Then you can texture them.  (at that point you can get a pointer to the texel data and do whatever you want with it).  Then move on to more advanced stuff like moving the camera around, etc.

 

http://www.swiftless.com/opengltuts.html

 

http://www.blitzbasic.com/Community/posts.php?topic=42662

 

I'm going to be writing my own rasteriser that converts a 3D world space into a 2D image that is drawn on the screen. I managed to do it in Java but I got a new graphics card which is CUDA enabled. It means I can do lots of parallel processing and make the program run a lot faster. Problem is that I don't know how to draw 2D images with C++ ;D

I was thinking about using OpenGL to draw the 2D image but I don't know how to create a window to set the OpenGL library to draw to. I'll look it up on teh googhels.

 

Ok, so yeah, follow the links I gave.  You just need to set up OGL and draw a full-screen textured quad w/ a texture that you create in memory.  Then get the pointer to the texels and you can set them to whatever RGB values you want.

Thanks!

Share this post


Link to post
Share on other sites

When it comes to OpenGL, Lets not forget about nehe's website. http://nehe.gamedev.net/ you can find plenty of tutorials there too.(Lesson 06 to 10 is what you really after)  Once you get the OpenGL up and running, rendering a 2D image is as simple as creating a quad with position vertices and texture coordinates, and binding the texture that you want to render. I must point out most of these tutorials are old. However, its a great start up for anyone who's new at it. 

Share this post


Link to post
Share on other sites

I started on graphics with nehe. It is old, but the nature of the pipeline has not changed overmuch since then, so you can easily move from there to newer API's and pick up new concepts.

Hmm... Maybe we should think about porting Nehe's tuts to a more recent API? Is he still around?

Edit -

*follows link*

*sees new page formatting*

lol, yeah, I'll email him and talk about it. Maybe GD can collab something.

 

Actually, I start classes on Monday, so I think I'll let it be for now.

Edited by Khatharr

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this