Jump to content

  • Log In with Google      Sign In   
  • Create Account


Rimher

Member Since 10 Sep 2012
Offline Last Active Oct 18 2013 04:57 PM
-----

Topics I've Started

Procedural Game Generation

04 October 2013 - 06:01 AM

I was getting started with a project with Libgdx and my idea was to make a procedural game, but I've never approached this topic. I'm very curious and eager to learn, do you guys have any idea where I could start?


Loading a Texture - Visual Artifacts

03 October 2012 - 03:28 AM

On my quest to keep learning OpenGL, I've gone as far as Nehe's Lesson 7 with loading a Crate texture.
But now I'm stuck. Since I'm on a Mac, I've had to write my own function to load a BMP file, and following this advice, I had my function ready and working, at least in tutorial 6. For #7, I've added my own class, that's just a wrapper that contains the information needed for data, width and height, and it's called BMPData.cpp.
Anyway, the problem is that the texture, in the end, appears like this.
Here's my code, I've tried doing anything with it, but have come up with not solution in the past two days, any help is really appriciated Posted Image
[source lang="cpp"]#include <SFML/Graphics.hpp>#include <SFML/Audio.hpp>#include <SFML/Network.hpp>#include <SFML/Window.hpp>#include <SFML/OpenGL.hpp>#include <glm-0.9.3.4/glm/glm.hpp>#include <fstream.h>#include "ResourcePath.hpp"// Include standard headers#include <stdio.h>#include <stdlib.h>#include <string.h>#include "BMPData.h"using namespace glm;GLfloat rtri, rquad;GLfloat xrot, yrot, zrot, xspeed, yspeed, z = -5.0f;std::string dataPath = "/Users/umbertosonnino/Documents/XCode/tobedeleted/tobedeleted/data/";bool lp, fp, light;GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f };GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };GLfloat LightPosition[] = { 0, 0, 2.0f, 1.0f, 1.0f };GLuint filter = 0, texture[3];BMPData *image;BMPData *loadBMP(std::string filename){ FILE* file = NULL; if(!filename.c_str()){ fprintf(stderr, "File name has not been handed to the program\n"); return NULL; } file = fopen(filename.c_str(), "rb"); if(file == NULL){ fprintf(stderr, "Error opening the file %s\n", filename.c_str()); return NULL; } unsigned long width = 0; unsigned long height = 0; unsigned long size = 0; fseek(file, 18, SEEK_SET); fread(&width, 4, 1, file); fread(&height, 4, 1, file); fseek(file, 0, SEEK_END); size = ftell(file) - 54; unsigned char* data = (unsigned char*) malloc(size); fseek(file, 54, SEEK_SET); fread(data, size, 1, file); image = new BMPData(data, width, height); fclose(file); return image;}unsigned int loadGLTextures(){ int status = false; BMPData *bmp; if( (bmp = loadBMP(dataPath+"Crate.bmp")) ){ status = true; glGenTextures(3, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)bmp->getWidth(), (GLsizei)bmp->getHeight(), 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmp->getData()); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)bmp->getWidth(), (GLsizei)bmp->getHeight(), 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmp->getData()); // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, (GLsizei)bmp->getWidth(), (GLsizei)bmp->getHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE, bmp->getData()); } if(bmp){ if(bmp->getData()){ bmp->~BMPData(); } free(bmp); } return status;}int draw(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(0.0f,0.0f,z); glRotatef(xrot,1.0f,0.0f,0.0f); glRotatef(yrot,0.0f,1.0f,0.0f); glBindTexture(GL_TEXTURE_2D, texture[filter]); glBegin(GL_QUADS); // Front Face glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face glNormal3f( 0.0f, 0.0f,-1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Face glNormal3f( 0.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Bottom Face glNormal3f( 0.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face glNormal3f( 1.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Left Face glNormal3f(-1.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); xrot+=xspeed; yrot+=yspeed; return true;}int initGL(){ //resizeGL function in Nehe glViewport(0, 0, 800, 600); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window gluPerspective(45.0f,(GLfloat)800/(GLfloat)600,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix //end of resize function if(!loadGLTextures()){ fprintf(stderr, "Error loading the bmp during initialization\n"); return false; } glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.3f, 0.5f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); glEnable(GL_LIGHT1); return true;}int main (int argc, const char * argv[]){ sf::Window window(sf::VideoMode(800, 600), "Nehe Lighting and Keyboard Tutotorial: Embracing OpenGL"); initGL(); do { // Process events sf::Event event; while (window.pollEvent(event)) { if(event.type == sf::Event::Resized){ glViewport(0, 0, event.size.width, event.size.height); } // Close window : exit if (event.type == sf::Event::Closed) window.close(); // Escape pressed : exit if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) window.close(); if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::L && !lp){ lp = true; light = !light; if(!light){ glDisable(GL_LIGHTING); } if(light){ glEnable(GL_LIGHTING); } } if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::L){ lp = false; } if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F && !fp){ fp = true; filter += 1; if(filter >2) filter = 0; } if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::F){ fp = false; } //When pressing up i'm moving the cube farther into distance if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::U) z += 0.2f; //When pressing down on the keyboard i'm moving the cuve closer to the screen if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard:[img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]) z-= 0.2f; if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up) xspeed -= 0.1f; if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down) xspeed += 0.1f; if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left) yspeed -= 0.1f; if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right) yspeed += 0.1f; } draw(); // Update the window window.display(); }while(window.isOpen()); return EXIT_SUCCESS;}[/source]

[SFML] Can't draw anything in OpenGL

29 September 2012 - 07:43 AM

Hello there! I've just recently started learning OpenGL, and I'm trying to use SFML as a working environment.
But I'm having my first problems.
I'm following Nehe's tutorial on how to get started in OpenGL, and I was trying to draw some simple shapes. The problem is, they do not appear on the screen! I clearly remember doing this on Windows at the time, but since I switched to Mac, everything seems much harder.

Anyway, here's the code...if anyone can help me, it'd be really appreciated.

[source lang="cpp"]#include <SFML/Graphics.hpp>#include <SFML/Audio.hpp>#include <SFML/Network.hpp>#include <SFML/Window.hpp>#include <SFML/OpenGL.hpp>#include "ResourcePath.hpp"// Include standard headers#include <stdio.h>#include <stdlib.h>using namespace glm;GLfloat rtri, rquad;GLfloat xrot, yrot, zrot;int draw(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5f, 0.0f, -6.0f); glRotatef(rtri, 0.0f, 1.0f, 0.0f); glBegin(GL_TRIANGLES); glColor3f(1.0f,0.0f,0.0f); // Red glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front) glColor3f(0.0f,1.0f,0.0f); // Green glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front) glColor3f(0.0f,0.0f,1.0f); // Blue glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front) glColor3f(1.0f,0.0f,0.0f); // Red glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right) glColor3f(0.0f,0.0f,1.0f); // Blue glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right) glColor3f(0.0f,1.0f,0.0f); // Green glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right) glColor3f(1.0f,0.0f,0.0f); // Red glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back) glColor3f(0.0f,1.0f,0.0f); // Green glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back) glColor3f(0.0f,0.0f,1.0f); // Blue glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back) glColor3f(1.0f,0.0f,0.0f); // Red glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left) glColor3f(0.0f,0.0f,1.0f); // Blue glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left) glColor3f(0.0f,1.0f,0.0f); // Green glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left) glEnd(); glLoadIdentity(); glTranslatef(1.5f,0.0f,-7.0f); // Move Right And Into The Screen glRotatef(rquad,1.0f,1.0f,1.0f); // Rotate The Cube On X, Y & Z glBegin(GL_QUADS); glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top) glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top) glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top) glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top) glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom) glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom) glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom) glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom) glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front) glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front) glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front) glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front) glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back) glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back) glVertex3f(-1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back) glVertex3f( 1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Back) glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left) glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left) glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left) glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left) glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right) glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right) glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right) glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right) glEnd(); // Done Drawing The Quad rtri+=0.2f; // Increase The Rotation Variable For The Triangle rquad-=0.15f; // Decrease The Rotation Variable For The Quad return true;}int initGL(){ glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.3f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return true;}int main (int argc, const char * argv[]){ sf::Window window(sf::VideoMode(800, 600), "OpenGL window"); initGL(); do { // Process events sf::Event event; while (window.pollEvent(event)) { if(event.type == sf::Event::Resized){ glViewport(0, 0, event.size.width, event.size.height); } // Close window : exit if (event.type == sf::Event::Closed) window.close(); // Escape pressed : exit if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) window.close(); } draw(); // Update the window window.display(); }while(window.isOpen()); return EXIT_SUCCESS;}[/source]

Getting started with OpenGL on OSX

10 September 2012 - 12:03 PM

Hello there,
I'm new over here, but I'm not exactly new to programming; I've studied Java, C, a bit of C++, and, since I got a Mac recently, I was trying to build my own knowledge of Obj-C.
Recently I was trying to learn a little bit of OpenGL, but almost everything that I've found online is windows-related. Can you guys help me find something suitable for OSX as well??

Thanks in advance

PARTNERS