Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Attemptedhippo

Member Since 04 Mar 2012
Offline Last Active Jul 24 2012 11:25 PM

Posts I've Made

In Topic: Where do I start learning c++

24 July 2012 - 10:53 PM

If i had to make a suggestion start with this for the 2d game aspect:
http://www.kathekont...uide/index.html (note: This tutorial set was written for win32 but it DOES work in Linux, not Mac thoughPosted Image)
Its an absolutely amazing in depth guide on how to build a 2d (overhead) game engine ONLY using c++ console. No need to worry about graphics yet, get the basics first.
A good C++ resource I would suggest is C++ Primer Plus by Stephen Prata its an amazing book for learning c++ with little programming knowledge.

Edit: Oh and I completely agree with DZee just write the source files in something like Notepad++ (google it) and then just compile using your terminal(or console i dont use mac) There is nothing more useful than seeing the raw compiler data when you have some kind of compile error.

In Topic: OpenGL Simple game

04 March 2012 - 09:23 PM

Thanks so much bro... lol it would be something so trivial but thus are computers :) Rep++

In Topic: OpenGL Simple game

04 March 2012 - 06:29 PM

Ok so after commenting out what i thought to be the problem code I still get the same issue. I now have no idea why it isnt working.

EDIT:
I have uncommented the lines to get two warnings(one for each call):
1>..\main.cpp(11): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>		  C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h(371) : see declaration of 'sprintf'

EDIT(again):
I tried using the Ctrl+F5 method and the console window still closes.

In Topic: OpenGL Simple game

04 March 2012 - 06:25 PM

ummm ive run the program in many ways.... all of them with the same result... using any way to run it, a console window will pop up and they close out within a fraction of a second. Like i said in my post "pixel format with nececary compatabilities cannot be found." is the error i get inside the console window that opens briefly. I have concluded that i am doing something wrong with storing and printing the text to screen. just incase you guys dont want to get the source from the site, i will throw it in code tags.

#include "main.h"
int pcResult = 0;
void Render() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
sprintf(string, "PC : %i", pcResult);
drawText(string, 10, 80);
sprintf(string, "Player : %i", playerResult);
drawText(string, 10, 120);

/****************************************************************************
**** I believe there are problems with the above section *******
****************************************************************************/

wall.left = wall.top = 0;
wall.right = WINDOW_WIDTH;
wall.bottom = WINDOW_HEIGHT;
DrawRectangle(ball);
if(Test_Ball_Wall(ball, wall) == FROM_RIGHT)
  Xspeed = -delta;
if(Test_Ball_Wall(ball, wall) == FROM_LEFT)
  Xspeed = delta;
if(Test_Ball_Wall(ball, wall) == FROM_TOP)
  Yspeed = -delta;
if(Test_Ball_Wall(ball, wall) == FROM_BOTTOM) {
  Yspeed = delta;
  pcResult += 1;
}
DrawRectangle(player_1);
player_1.left = mouse_x -30;
player_1.right = mouse_x +30;
if(Test_Ball_Player(ball, player_1) == true)
  Yspeed = -delta;
glutSwapBuffers();
}
int main(int argc, char** argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GL_DOUBLE | GL_RGBA);
glutInitWindowSize(795, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Pong Test");
Setting();
glutDisplayFunc(Render);
glutIdleFunc(Render);
glutTimerFunc(1, Timer, 1);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutSpecialFunc(inputKey);
//glutSpecialUpFunc(upKey);
glutPassiveMotionFunc(MouseMotion);
glutMainLoop();
system("pause");
return 0;


#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<stdio.h>
#define FROM_RIGHT  1
#define FROM_LEFT   2
#define FROM_TOP    3
#define FROM_BOTTOM 4
static int WINDOW_WIDTH, WINDOW_HEIGHT;
int playerResult = 0;
static float Xspeed = 1, Yspeed = 1;
static float delta = 1;
char string[100];
struct RECTA {
float left, top, right, bottom;
};
RECTA ball = {100, 100, 120, 120};
RECTA wall;
RECTA player_1 = {0, 490, 40, 500};
void DrawRectangle (RECTA rect) {
glBegin(GL_QUADS);
glVertex2f(rect.left, rect.bottom);
glVertex2f(rect.right, rect.bottom);
glVertex2f(rect.right, rect.top);
glVertex2f(rect.left, rect.top);
glEnd();
}
void Timer(int v) {
ball.right += Xspeed;
ball.left += Xspeed;
ball.top += Yspeed;
ball.bottom += Yspeed;
glutTimerFunc(1, Timer, 1);
}
void drawText(char* string, int x, int y) {
char *c;
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(0.1, -0.1, 1);
for(c = string; *c != '\0'; c++){
  glutStrokeCharacter(GLUT_STROKE_ROMAN, *c);
}
glPopMatrix();
}
int Test_Ball_Wall (RECTA ball, RECTA wall) {
if(ball.right >= wall.right)
  return FROM_RIGHT;
if(ball.left <= wall.left)
  return FROM_LEFT;
if(ball.top <= wall.top)
  return FROM_TOP;
if(ball.bottom >= wall.bottom)
  return FROM_BOTTOM;

else return 0;
}
bool Test_Ball_Player(RECTA ball, RECTA player) {
if(ball.bottom >=player.top && ball.left >= player.left && ball.right <= player.right){
  playerResult++;
  return true;
}
return false;
}
void keyboard (unsigned char key, int x, int y) {
switch (key) {
  case 27:
   exit(0);
  break;
}
}
void inputKey (int key, int x, int y){
switch (key){
case GLUT_KEY_LEFT:
  break;
case GLUT_KEY_RIGHT:
  break;
case GLUT_KEY_UP:
  break;
case GLUT_KEY_DOWN:
  break;
}
}
void upKey(int key, int x, int y) {
}
static int mouse_x = 0;
void MouseMotion (int x, int y) {
mouse_x = x;
}
//OpenGL settings
void Setting(void) {
glClearColor(0, 0, 0, 0);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
void reshape (int w, int h) {
WINDOW_WIDTH = w;
WINDOW_HEIGHT = h;

glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

PARTNERS