Author Topic: [C]OpenGLDemo.1  (Read 3427 times)

0 Members and 2 Guests are viewing this topic.

Offline Zer0Flag

  • Serf
  • *
  • Posts: 20
  • Cookies: 5
    • View Profile
[C]OpenGLDemo.1
« on: September 02, 2011, 11:57:16 pm »
Hey ,

I played a bit with OpenGL and here is the result. First time that I coded with OpenGL so don***180;t freak out if its worse :).
http://www.youtube.com/watch?v=MmvviVVdkzE
Code: [Select]
//Zer0Flag @ drunken-nanomites.org

#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <GL/glut.h>
#include <iostream>
#include <time.h>

using namespace std;

float fRotation[20] = { 0.0f };
float fKoordSize = 60.0f;
float fJump = 0.0f;

time_t ExecutionTime = NULL;

void changeSize(int iWidth, int iHeight) {
if (iHeight <= 0)
{
iHeight = 1;
}

float ratio =  iWidth / iHeight;

glViewport(0, 0, iWidth, iHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, ratio, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void renderScene(void) {
Sleep(50);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

time_t CurrentTime = time(NULL);
long ullCurrentTicks = CurrentTime - ExecutionTime;

if (ullCurrentTicks <= 11)
{
switch (ullCurrentTicks)
{
case 1:
for ( int Ix = 0 ; Ix <= 4; Ix += 4)
{
for ( int Iy = 0; Iy <= 4; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 2:
for ( int Ix = 0 ; Ix <= 8; Ix += 4)
{
for ( int Iy = 0; Iy <= 8; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 3:
for ( int Ix = 0 ; Ix <= 12; Ix += 4)
{
for ( int Iy = 0; Iy <= 12; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 4:
for ( int Ix = 0 ; Ix <= 16; Ix += 4)
{
for ( int Iy = 0; Iy <= 16; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 5:
for ( int Ix = 0 ; Ix <= 20; Ix += 4)
{
for ( int Iy = 0; Iy <= 20; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 6:
for ( int Ix = 0 ; Ix <= 24; Ix += 4)
{
for ( int Iy = 0; Iy <= 24; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 7:
for ( int Ix = 0 ; Ix <= 28; Ix += 4)
{
for ( int Iy = 0; Iy <= 28; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 8:
for ( int Ix = 0 ; Ix <= 32; Ix += 4)
{
for ( int Iy = 0; Iy <= 32; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 9:
for ( int Ix = 0 ; Ix <= 36; Ix += 4)
{
for ( int Iy = 0; Iy <= 36; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 10:
for ( int Ix = 0 ; Ix <= 40; Ix += 4)
{
for ( int Iy = 0; Iy <= 40; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
case 11:
for ( int Ix = 0 ; Ix <= 44; Ix += 4)
{
for ( int Iy = 0; Iy <= 44; Iy += 4)
{
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef(((fKoordSize/2) - 8)* (-1) + Ix,((fKoordSize/2) - 8)* (-1) + Iy,0);
glutWireCube(2.0);
}
}
break;
}
}
if (ullCurrentTicks > 11 && ullCurrentTicks <= 18)
{
int i = 0;

for ( int Ix = 0 ; Ix <= 60 ; Ix += 4)
{
for(int Iy = 0 ; Iy <= 60 ; Iy += 4)
{
fJump = (((rand() % 8) + 1 ));
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef((fKoordSize/2 * (-1)) + Ix,(fKoordSize/2 * (-1)) + Iy,fJump);
glutWireCube(2.0);
}
}
}
if (ullCurrentTicks > 18 && ullCurrentTicks <= 25)
{
int i = 0;

for ( int Ix = 0 ; Ix <= 60 ; Ix += 4)
{
for(int Iy = 0 ; Iy <= 60 ; Iy += 4)
{
fJump = (((rand() % 8) + 1 ));
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glTranslatef((fKoordSize/2 * (-1)) + Ix,(fKoordSize/2 * (-1)) + Iy,fJump);
glRotatef(fRotation[i],1.0f,1.0f,0.0f);
glutWireCube(2.0);

fRotation[i++] += 1.0f;
}
}
}
if (ullCurrentTicks > 25 && ullCurrentTicks <= 32)
{
int i = 0;

for ( int Ix = 0 ; Ix <= 60 ; Ix += 4)
{
for(int Iy = 0 ; Iy <= 60 ; Iy += 4)
{
fJump = (((rand() % 8) + 1 ));
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gluLookAt(0.0f, 0.0f,fKoordSize,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);

switch ((((rand() % 30) + 10) /10))
{
case 1:
glColor3f(0.5f,0.0f,0.0f);
break;
case 2:
glColor3f(0.0f,0.5f,0.0f);
break;
case 3:
glColor3f(0.0f,0.0f,0.8f);
break;
}

glTranslatef((fKoordSize/2 * (-1)) + Ix,(fKoordSize/2 * (-1)) + Iy,fJump);
glRotatef(fRotation[i],1.0f,1.0f,0.0f);
glutWireCube(2.0);

fRotation[i++] += 1.0f;
}
}
}
if(ullCurrentTicks > 32)
{

}
glutSwapBuffers();
}

void processNormalKeys(unsigned char key, int x, int y) {
if (key == 27) // Exit on ESC
{
exit(0);
}
}

void main(int argc, char **argv) {

ExecutionTime = time(NULL);


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("OpenGL Tests");

glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);

glutKeyboardFunc(processNormalKeys);

glutMainLoop();
}
~0
« Last Edit: September 03, 2011, 12:33:08 am by Zer0Flag »

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [C]OpenGLDemo.1
« Reply #1 on: September 03, 2011, 12:56:23 am »
Pretty good, I tried openGL a few years back. Couldn't do more than draw a square on the screen ;)
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: [C]OpenGLDemo.1
« Reply #2 on: September 13, 2011, 11:49:18 pm »
sorry I have never used OpenGl, how did you install it? (sorry for the noobis question)
I checked the site but I saw so much things to download. I just don't now where to start...
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [C]OpenGLDemo.1
« Reply #3 on: September 14, 2011, 07:19:15 am »
<..>(sorry for the noobis question) <..>
God.. people should STOP admitting that they are "noobs" and calling themselves names. Everyone is equal and everyone has more experience then the other in some other fields and not just coding :(

iMorg

  • Guest
Re: [C]OpenGLDemo.1
« Reply #4 on: September 18, 2011, 03:34:41 am »
sorry I have never used OpenGl, how did you install it? (sorry for the noobis question)
I checked the site but I saw so much things to download. I just don't now where to start...

Using glut is pretty much the easiest way to start writing opengl software. You just download the library, put the headers into your compilers "gl" header path and have your project link to the libraries.

This will get you started
http://www.gamedev.net/page/resources/_/reference/programming/sweet-snippets/basics-of-glut-r1680

v1 of the opengl red book is also available online if you dont want to go download the new editions.

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: [C]OpenGLDemo.1
« Reply #5 on: September 18, 2011, 10:21:11 am »
Using glut is pretty much the easiest way to start writing opengl software. You just download the library, put the headers into your compilers "gl" header path and have your project link to the libraries.

This will get you started
http://www.gamedev.net/page/resources/_/reference/programming/sweet-snippets/basics-of-glut-r1680

v1 of the opengl red book is also available online if you dont want to go download the new editions.
Thank you very much!
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline john_engit

  • NULL
  • Posts: 3
  • Cookies: 0
    • View Profile
Re: [C]OpenGLDemo.1
« Reply #6 on: December 01, 2011, 11:04:57 am »
awesome  :)

PublicEnemy

  • Guest
Re: [C]OpenGLDemo.1
« Reply #7 on: December 01, 2011, 08:04:22 pm »
God.. people should STOP admitting that they are "noobs"
Exactly, don't call yourself a noob - that is my job.