Transfering from java applets to console c++

Started by
5 comments, last by M0dSe7en 12 years, 4 months ago

Im 16 i started programming late in 7th grade i started with python, worked my way up with java.

i've been coding java for about a year or so now and i've made several java 2d games and lots of console based programs. However, Now i wanted to just begin into very basic 2d and 3d mechanics of c++.

I know that opengl is mainly meant for c++ and that there is java 3d but i want to be a game programmer and i need to start with c++ early on. So my question is what should i start with first?

I was thinking something along the lines of looking at an open source simple game, however i doubt i would know where to go with it as of right now.

Also I tried finding some source for a rotating cube but when i compiled it in dev C++ it got an error on the imports in fact the only bit of source that worked for me was the example provided with the ide, which i could not for the life of me decipher.

any info helps guys but im not new to programming so i just need to know how YOU all started in the simplest fashion, unfortunately the high school programming at my school is a joke and consists of a football coach that copies and pastes code off of google and presents everything in powerpoint so you guys are my only hope right now lol please any info appreciated.

NOTE: Please no engines unless they are intermediate level no Game Maker or Unity 3D thanx.

oh also here's the example provided with dev c++ it makes a spinning RGB triangle.

/**************************
* Includes
*
**************************/

#include <windows.h>
#include <gl/gl.h>


/**************************
* Function Declarations
*
**************************/

LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);


/**************************
* WinMain
*
**************************/

int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;

/* register window class */
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass (&wc);

/* create main window */
hWnd = CreateWindow (
"GLSample", "OpenGL Sample",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 256, 256,
NULL, NULL, hInstance, NULL);

/* enable OpenGL for the window */
EnableOpenGL (hWnd, &hDC, &hRC);

/* program main loop */
while (!bQuit)
{
/* check for messages */
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{
/* OpenGL animation code goes here */

glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);

glPushMatrix ();
glRotatef (theta, 0.0f, 0.0f, 1.0f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f); /* I DID NOTICE THAT COLOR3f IS THE RGB COLORS HOWEVER I DONT UNDERSTAND 1.0 is that out of 255 colors?*/
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.87f, -0.5f);
glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.87f, -0.5f);
glEnd ();
glPopMatrix ();

SwapBuffers (hDC);

theta += 1.0f;
Sleep (1);
}
}

/* shutdown OpenGL */
DisableOpenGL (hWnd, hDC, hRC);

/* destroy the window explicitly */
DestroyWindow (hWnd);

return msg.wParam;
}


/********************
* Window Procedure
*
********************/

LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{

switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage (0);
return 0;

case WM_DESTROY:
return 0;

case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;

default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
}


/*******************
* Enable OpenGL
*
*******************/

void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;

/* get the device context (DC) */
*hDC = GetDC (hWnd);

/* set the pixel format for the DC */
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);

/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );

}


/******************
* Disable OpenGL
*
******************/

void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}


Advertisement

Im 16 i started programming late in 7th grade i started with python, worked my way up with java.

i've been coding java for about a year or so now and i've made several java 2d games and lots of console based programs. However, Now i wanted to just begin into very basic 2d and 3d mechanics of c++.

I know that opengl is mainly meant for c++ and that there is java 3d but i want to be a game programmer and i need to start with c++ early on. So my question is what should i start with first?


Firstly, to nitpick, I believe that nature of OpenGL is more aimed towards C than it is towards C++. Secondly, if you are doing okay with Java, you should probably stick with just that, at least for a while longer. There is not much you can accomplish with C++ that you can't with Java. But, to answer the question of where to start, obviously you want to read some kind of text to familiarize yourself with the fundamental features of the language. From that point on, really, it just comes down to practice. There are a few libraries you can use for graphics, such as SFML, SDL, native OS API (Win32, Cocoa, etc.), Allegro, and for 3D you can check out OpenGL and DirectX. Once you master all that, the rest is not much different from what you would do with Java. Draw images, move images, rinse repeat.


I was thinking something along the lines of looking at an open source simple game, however i doubt i would know where to go with it as of right now.

Also I tried finding some source for a rotating cube but when i compiled it in dev C++ it got an error on the imports in fact the only bit of source that worked for me was the example provided with the ide, which i could not for the life of me decipher.


Off the bat I can tell you that using Dev C++ is ill advised. It is outdated and vastly obsolete. I have no idea why virtually everyone starting out with C++ ends up with this IDE, but, it's best if you switch to a more modern IDE such as VC++ (2008 or 2010) or Code::Blocks.


any info helps guys but im not new to programming so i just need to know how YOU all started in the simplest fashion, unfortunately the high school programming at my school is a joke and consists of a football coach that copies and pastes code off of google and presents everything in powerpoint so you guys are my only hope right now lol please any info appreciated.


Are you serious about the football coach thing? XD Who let him teach that class?


NOTE: Please no engines unless they are intermediate level no Game Maker or Unity 3D thanx.

oh also here's the example provided with dev c++ it makes a spinning RGB triangle.

// Code removed




The code is a combination of Win32 and OpenGL. Win32 manages the windows, input, and all that good stuff, whereas OpenGL is specialized to handle graphics only. There is GLUT that helps it stand on it's own, but it's usually preferable to use it with another library.

Yo dawg, don't even trip.



Firstly, to nitpick, I believe that nature of OpenGL is more aimed towards C than it is towards C++. Secondly, if you are doing okay with Java, you should probably stick with just that, at least for a while longer. There is not much you can accomplish with C++ that you can't with Java. But, to answer the question of where to start, obviously you want to read some kind of text to familiarize yourself with the fundamental features of the language. From that point on, really, it just comes down to practice. There are a few libraries you can use for graphics, such as SFML, SDL, native OS API (Win32, Cocoa, etc.), Allegro, and for 3D you can check out OpenGL and DirectX. Once you master all that, the rest is not much different from what you would do with Java. Draw images, move images, rinse repeat


thanks for the info i didn't know that, in java i don't really rely on any external libraries so it's good to know that i have choices, also if you could recommend a book that would be appreciated as far as the c# c++ your saying i need to know.


Off the bat I can tell you that using Dev C++ is ill advised. It is outdated and vastly obsolete. I have no idea why virtually everyone starting out with C++ ends up with this IDE, but, it's best if you switch to a more modern IDE such as VC++ (2008 or 2010) or Code::Blocks.





Are you serious about the football coach thing? XD Who let him teach that class?

sadly yes lol, unfortunately our new school filled with smart boards (touch screen boards that look like whiteboards but are touchpads for a projecter image to fit on them.) in every room apparently forgot to hire anyone competent as far as programming or even tech advice for that matter, lol the school is also terrible for security, they paid for novell but in Middle school i managed to shutdown all the computers with a hidden MS-DOS prompt, just temporarily, lol but in high school they leave a DOS prompt in the startup menu?! haven't done anything major but it is pretty entertaining to see a teacher complain about a virus when they startup their computer and see 50 notepads open up lol.

Well, I made no mention of C# in my post and frankly, I have never used it before, nothing worthy of the "project" title anyway.

I have never actually used a book to learn C++ XD I did have a book on C++, but I have never read past chapter 2 because it was coma-inducing. The concepts carry from language to language. You'll have to read up on pointers and memory management and certain features of classes. Once you start using the language, you'll be able to explore it more along the way. Other than that, I'm afraid someone else will have to point you to a good text.

Yo dawg, don't even trip.


unfortunately the high school programming at my school is a joke and consists of a football coach that copies and pastes code off of google and presents everything in powerpoint


That's sad. Though I suppose it's good motivation to learn to teach yourself, which in the tech industry is something you do year in and year out anyway.


Well, I made no mention of C# in my post and frankly, I have never used it before, nothing worthy of the "project" title anyway.

I have never actually used a book to learn C++ XD I did have a book on C++, but I have never read past chapter 2 because it was coma-inducing. The concepts carry from language to language. You'll have to read up on pointers and memory management and certain features of classes. Once you start using the language, you'll be able to explore it more along the way. Other than that, I'm afraid someone else will have to point you to a good text.


lol thanks, that's funny because i too can't handle books to me there all theory rather than snippets or practical information. it seems more to me like history of software design rather than actual hands on code. i do some people that learned it that way but my main resource has been google and youtube, in particular thenewboston, he's really good at explaining however the most unfortunate thing was that i was doing really good with his java tutorials but he stopped halfway through his 2d right before he was going into 3d lol so now i need to find something new. i'm not planning to make an engine or a standalone game just want to experiment for right now maybe make a spinning cube or a 3d signature or something cool.

[quote name='M0dSe7en' timestamp='1322523596' post='4888620']

unfortunately the high school programming at my school is a joke and consists of a football coach that copies and pastes code off of google and presents everything in powerpoint


That's sad. Though I suppose it's good motivation to learn to teach yourself, which in the tech industry is something you do year in and year out anyway.


[/quote]

lol yeah i've always been independent as far as computers but the thing is it's hard to find examples or tutorials on c++ because it's so extensive, it lacks the simple nature of other languages that are pretty self reliant like java where you use very little external imports if any other than the Java Virtual Machine default libraries.

This topic is closed to new replies.

Advertisement