can anyone figure out why this wont work ?

Started by
8 comments, last by Randall Perkins 11 years, 3 months ago

im trying to get use to using opengl with sdl and when i try to bind a texture and apply it to a GL_QUAD it wont work ?

im going attach a zip with the contents of the application below (IDE is CodeBlocks)

Image of screen

21z9ts.png

if anyone could help it would mean a lot! Thank you for your time

Advertisement
You need to declare global variables with external linkage, otherwise, each c file will have its own copy of those variables. Calling graphics_engine_init will modify graphics.c's version of screen and menu_image. See problem #4 in Organizing Code Files in C and C++.

thanks fastcall22 im going work on this, ill let you know if i get it to work or not

Fastcall22 i did what it said and it still just a black screen ?

i reuploaded a new copy of the code with a compiled version in the bin/debug folder

i converted all the code to a single file

http://pastie.org/5722381

and still the same result ?????????

You are rendering your quad along the wrong axis. The camera (screen) faces along the Z-axis - you are treating it as facing along the Y-axis.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

swiftcoder should i use glTranslatef() or go and change the glVertex3f() in the quads ?


#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <GL/gl.h>
#include <GL/glu.h>

#ifndef GRAP_HEADER_H
#define GRAP_HEADER_H
    SDL_Surface *screen;
    GLuint menu_image;
#endif

void graphics_engine_init();
void graphics_engine_exit();
GLuint LoadTexture(char *filename,int textw,int texth);
void DrawTexture(int x, int y, int textw,int texth, GLuint textureid);


No, not quite. (You're looking at "Fixing problem #3". (I think.))

Quickfix:
// graphics.h
extern SDL_Surface *screen;
extern GLuint menu_image;

// graphics.cpp
SDL_Surface *screen;
GLuint menu_image;

When a source file encounters an "extern", it is told that this variable exists, but resides elsewhere. Without the extern, each source file refers to its own version of those variables. When your program is linked, all of the externed variables are hooked up to the (one and only) location.

(Quite a shoddy explanation, but I hope it helps.)

[quote name='MrPhoenix' timestamp='1358553041' post='5023030']
swiftcoder should i use glTranslatef() or go and change the glVertex3f() in the quads?[/quote]

I'd switch it right in the vertex calls, at least for now. Better to get it working before adding further complexity.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Ok i fixed the quad and the view but the the quad wont accept the texture ???/

it just a plain quad ?

This topic is closed to new replies.

Advertisement